rename file before unlinking to avoid EBUSY failures.
authorjbj <devnull@localhost>
Thu, 18 Feb 1999 17:21:50 +0000 (17:21 +0000)
committerjbj <devnull@localhost>
Thu, 18 Feb 1999 17:21:50 +0000 (17:21 +0000)
CVS patchset: 2810
CVS date: 1999/02/18 17:21:50

CHANGES
lib/cpio.c

diff --git a/CHANGES b/CHANGES
index 26e8256..242a097 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,5 @@
 2.90 -> 2.91
+       - rename file before unlinking to avoid EBUSY failures.
        - add callbacks for installer updates while doing URL xfers.
        - resurrect http queries/verifies.
        - create rpmbzio.c to avoid implicit dependence on libbz2 for installer.
index 2fcfe3d..2435e64 100644 (file)
@@ -354,9 +354,24 @@ static int expandRegular(CFD_t * cfd, struct cpioHeader * hdr,
     struct cpioCallbackInfo cbInfo;
     struct stat sb;
 
-    if (!lstat(hdr->path, &sb))
-       if (unlink(hdr->path))
+    /* Rename the old file before attempting unlink to avoid EBUSY errors */
+    if (!lstat(hdr->path, &sb)) {
+       strcpy(buf, hdr->path);
+       strcpy(buf, "-RPMDELETE");
+       if (rename(hdr->path, buf)) {
+           fprintf(stderr, _("can't rename %s to %x: %s\n"),
+               hdr->path, buf, strerror(errno));
+            return CPIOERR_UNLINK_FAILED;
+       }
+
+       if (unlink(buf)) {
+           fprintf(stderr, _("can't unlink %s: %s\n"),
+               buf, strerror(errno));
+#if 0
            return CPIOERR_UNLINK_FAILED;
+#endif
+       }
+    }
 
     out = fdOpen(hdr->path, O_CREAT | O_WRONLY, 0);
     if (fdFileno(out) < 0)