Skip to content

Commit bb17a98

Browse files
committed
Print file name and errno string on rmtree failure.
Backpatch to 8.0.X.
1 parent c6521b1 commit bb17a98

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/port/dirmod.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Win32 (NT, Win2k, XP). replace() doesn't work on Win95/98/Me.
1111
*
1212
* 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 $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -350,6 +350,7 @@ fnames(char *path)
350350
return filenames;
351351
}
352352

353+
353354
/*
354355
* fnames_cleanup
355356
*
@@ -366,6 +367,7 @@ fnames_cleanup(char **filenames)
366367
pfree(filenames);
367368
}
368369

370+
369371
/*
370372
* rmtree
371373
*
@@ -398,39 +400,41 @@ rmtree(char *path, bool rmtopdir)
398400
snprintf(filepath, MAXPGPATH, "%s/%s", path, *filename);
399401

400402
if (stat(filepath, &statbuf) != 0)
401-
{
402-
fnames_cleanup(filenames);
403-
return false;
404-
}
403+
goto report_and_fail;
405404

406405
if (S_ISDIR(statbuf.st_mode))
407406
{
408407
/* call ourselves recursively for a directory */
409408
if (!rmtree(filepath, true))
410409
{
410+
/* we already reported the error */
411411
fnames_cleanup(filenames);
412412
return false;
413413
}
414414
}
415415
else
416416
{
417417
if (unlink(filepath) != 0)
418-
{
419-
fnames_cleanup(filenames);
420-
return false;
421-
}
418+
goto report_and_fail;
422419
}
423420
}
424421

425422
if (rmtopdir)
426423
{
427424
if (rmdir(path) != 0)
428-
{
429-
fnames_cleanup(filenames);
430-
return false;
431-
}
425+
goto report_and_fail;
432426
}
433427

434428
fnames_cleanup(filenames);
435429
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;
436440
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy