10
10
* Win32 (NT, Win2k, XP). replace() doesn't work on Win95/98/Me.
11
11
*
12
12
* IDENTIFICATION
13
- * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.34 2004/12/31 22:03:53 pgsql Exp $
13
+ * $PostgreSQL: pgsql/src/port/dirmod.c,v 1.35 2005/02/13 16:50:44 momjian Exp $
14
14
*
15
15
*-------------------------------------------------------------------------
16
16
*/
@@ -350,6 +350,7 @@ fnames(char *path)
350
350
return filenames ;
351
351
}
352
352
353
+
353
354
/*
354
355
* fnames_cleanup
355
356
*
@@ -366,6 +367,7 @@ fnames_cleanup(char **filenames)
366
367
pfree (filenames );
367
368
}
368
369
370
+
369
371
/*
370
372
* rmtree
371
373
*
@@ -398,39 +400,41 @@ rmtree(char *path, bool rmtopdir)
398
400
snprintf (filepath , MAXPGPATH , "%s/%s" , path , * filename );
399
401
400
402
if (stat (filepath , & statbuf ) != 0 )
401
- {
402
- fnames_cleanup (filenames );
403
- return false;
404
- }
403
+ goto report_and_fail ;
405
404
406
405
if (S_ISDIR (statbuf .st_mode ))
407
406
{
408
407
/* call ourselves recursively for a directory */
409
408
if (!rmtree (filepath , true))
410
409
{
410
+ /* we already reported the error */
411
411
fnames_cleanup (filenames );
412
412
return false;
413
413
}
414
414
}
415
415
else
416
416
{
417
417
if (unlink (filepath ) != 0 )
418
- {
419
- fnames_cleanup (filenames );
420
- return false;
421
- }
418
+ goto report_and_fail ;
422
419
}
423
420
}
424
421
425
422
if (rmtopdir )
426
423
{
427
424
if (rmdir (path ) != 0 )
428
- {
429
- fnames_cleanup (filenames );
430
- return false;
431
- }
425
+ goto report_and_fail ;
432
426
}
433
427
434
428
fnames_cleanup (filenames );
435
429
return true;
430
+
431
+ report_and_fail :
432
+
433
+ #ifndef FRONTEND
434
+ elog (WARNING , "could not remove file or directory \"%s\": %m" , filepath );
435
+ #else
436
+ fprintf (stderr , "could not remove file or directory \"%s\": %s\n" , filepath , strerror (errno ));
437
+ #endif
438
+ fnames_cleanup (filenames );
439
+ return false;
436
440
}
0 commit comments