|
|
@@ -206,18 +206,18 @@ check_rename(struct file *src, struct file *dst)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-static int
|
|
|
+static void
|
|
|
file_copy(const char *src, const char *dst)
|
|
|
{
|
|
|
int srcfd, dstfd;
|
|
|
|
|
|
srcfd = open(src, O_RDONLY);
|
|
|
if (srcfd < 0)
|
|
|
- return -1;
|
|
|
+ ohshite(_("unable to open file '%s'"), src);
|
|
|
|
|
|
dstfd = creat(dst, 0600);
|
|
|
if (dstfd < 0)
|
|
|
- return -1;
|
|
|
+ ohshite(_("unable to create file '%s'"), dst);
|
|
|
|
|
|
/* FIXME: leaves a dangling destination file on error. */
|
|
|
|
|
|
@@ -226,36 +226,31 @@ file_copy(const char *src, const char *dst)
|
|
|
close(srcfd);
|
|
|
|
|
|
if (fsync(dstfd))
|
|
|
- return -1;
|
|
|
+ ohshite(_("unable to sync file '%s'"), dst);
|
|
|
if (close(dstfd))
|
|
|
- return -1;
|
|
|
+ ohshite(_("unable to close file '%s'"), dst);
|
|
|
|
|
|
file_copy_perms(src, dst);
|
|
|
-
|
|
|
- return 0;
|
|
|
}
|
|
|
|
|
|
-static int
|
|
|
+static void
|
|
|
rename_mv(const char *src, const char *dst)
|
|
|
{
|
|
|
char *tmpdst;
|
|
|
|
|
|
if (rename(src, dst) == 0)
|
|
|
- return 0;
|
|
|
+ return;
|
|
|
|
|
|
m_asprintf(&tmpdst, "%s%s", dst, ".dpkg-divert.tmp");
|
|
|
|
|
|
/* If a simple rename didn't work try an atomic copy, rename, unlink
|
|
|
* instead. */
|
|
|
- if (file_copy(src, tmpdst) != 0)
|
|
|
- return -1;
|
|
|
+ file_copy(src, tmpdst);
|
|
|
|
|
|
if (rename(tmpdst, dst) != 0)
|
|
|
- return -1;
|
|
|
+ ohshite(_("cannot rename '%s' to '%s'"), tmpdst, dst);
|
|
|
|
|
|
free(tmpdst);
|
|
|
-
|
|
|
- return 0;
|
|
|
}
|
|
|
|
|
|
static void
|
|
|
@@ -269,9 +264,7 @@ file_rename(struct file *src, struct file *dst)
|
|
|
ohshite(_("rename: remove duplicate old link '%s'"),
|
|
|
src->name);
|
|
|
} else {
|
|
|
- if (rename_mv(src->name, dst->name))
|
|
|
- ohshite(_("cannot rename '%s' to '%s'"),
|
|
|
- src->name, dst->name);
|
|
|
+ rename_mv(src->name, dst->name);
|
|
|
}
|
|
|
}
|
|
|
|