From 6f35dcf84bc859aefe8c4bf54a1d29aeb3a6a39a Mon Sep 17 00:00:00 2001 From: jbj Date: Thu, 18 Feb 1999 17:21:50 +0000 Subject: [PATCH] rename file before unlinking to avoid EBUSY failures. CVS patchset: 2810 CVS date: 1999/02/18 17:21:50 --- CHANGES | 1 + lib/cpio.c | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 26e8256..242a097 100644 --- 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. diff --git a/lib/cpio.c b/lib/cpio.c index 2fcfe3d..2435e64 100644 --- a/lib/cpio.c +++ b/lib/cpio.c @@ -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) -- 2.7.4