aboutsummaryrefslogtreecommitdiff
path: root/src/diskio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/diskio.c')
-rw-r--r--src/diskio.c107
1 files changed, 48 insertions, 59 deletions
diff --git a/src/diskio.c b/src/diskio.c
index 9574014..99d3b54 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -66,13 +66,13 @@ create_hierarchy(char *dir, size_t baselen)
if (stat(dir, &st) == 0) {
if (!S_ISDIR(st.st_mode)) {
- logmsg(LOG_ERR, _("component %s is not a directory"),
+ wy_log(LOG_ERR, _("component %s is not a directory"),
dir);
return 1;
}
return 0;
} else if (errno != ENOENT) {
- logmsg(LOG_ERR, _("cannot stat file %s: %s"), dir,
+ wy_log(LOG_ERR, _("cannot stat file %s: %s"), dir,
strerror(errno));
return 1;
}
@@ -80,7 +80,7 @@ create_hierarchy(char *dir, size_t baselen)
p = strrchr(dir, '/');
if (p) {
if (p - dir + 1 < baselen) {
- logmsg(LOG_ERR, _("base directory %s does not exist"),
+ wy_log(LOG_ERR, _("base directory %s does not exist"),
dir);
return 1;
}
@@ -92,7 +92,7 @@ create_hierarchy(char *dir, size_t baselen)
if (p)
*p = '/';
if (mkdir(dir, MKDIR_PERMISSIONS)) {
- logmsg(LOG_ERR, _("cannot create directory %s: %s"),
+ wy_log(LOG_ERR, _("cannot create directory %s: %s"),
dir, strerror(errno));
rc = 1;
}
@@ -132,14 +132,14 @@ copy_file(const char *file, const char *dst_file)
in_fd = open(file, O_RDONLY);
if (in_fd == -1) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot open source file %s for reading: %s"),
file, strerror(errno));
return 1;
}
if (fstat(in_fd, &st)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot stat source file %s: %s"),
file, strerror(errno));
close(in_fd);
@@ -148,7 +148,7 @@ copy_file(const char *file, const char *dst_file)
out_fd = creat(dst_file, CREAT_PERMISSIONS);
if (out_fd == -1) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot create destination file %s: %s"),
dst_file, strerror(errno));
close(in_fd);
@@ -171,20 +171,20 @@ copy_file(const char *file, const char *dst_file)
rest = fsize > bufsize ? bufsize : fsize;
rdbytes = read(in_fd, buf, rest);
if (rdbytes == -1) {
- logmsg(LOG_ERR, _("unexpected error reading %s: %s"),
+ wy_log(LOG_ERR, _("unexpected error reading %s: %s"),
file, strerror(errno));
rc = 1;
break;
}
rest = write(out_fd, buf, rdbytes);
if (rest == -1) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("unexpected error writing to %s: %s"),
dst_file, strerror(errno));
rc = 1;
break;
} else if (rest != rdbytes) {
- logmsg(LOG_ERR, _("short write on %s"), dst_file);
+ wy_log(LOG_ERR, _("short write on %s"), dst_file);
rc = 1;
}
fsize -= rdbytes;
@@ -208,15 +208,15 @@ do_move_file(const char *file, const char *dst_file)
if (rename(file, dst_file)) {
if (errno == EXDEV) {
if (copy_file(file, dst_file)) {
- logmsg(LOG_CRIT, _("cannot copy %s to %s: %s"),
+ wy_log(LOG_CRIT, _("cannot copy %s to %s: %s"),
file, dst_file, strerror(errno));
rc = 1;
} else if (unlink(file)) {
- logmsg(LOG_ERR, _("cannot unlink %s: %s"),
+ wy_log(LOG_ERR, _("cannot unlink %s: %s"),
file, strerror(errno));
}
} else {
- logmsg(LOG_CRIT, _("cannot move %s to %s: %s"),
+ wy_log(LOG_CRIT, _("cannot move %s to %s: %s"),
file, dst_file, strerror(errno));
rc = 1;
}
@@ -231,8 +231,7 @@ tar_append_file(const char *archive, const char *file)
{
const char *argv[6];
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("tarring %s to %s"), file, archive);
+ wy_debug(1, (_("tarring %s to %s"), file, archive));
if (dry_run_mode) {
UPDATE_STATS(STAT_ARCHIVES);
return 0;
@@ -252,7 +251,7 @@ tar_append_file(const char *archive, const char *file)
case exec_fail:
case exec_error:
- logmsg(LOG_ERR, _("cannot archive %s"), file);
+ wy_log(LOG_ERR, _("cannot archive %s"), file);
break;
}
@@ -286,13 +285,11 @@ backup_file(const char *dst_file, const char *dst_dir, const char *file,
file_name = concat_dir(adir, file, NULL);
if (access(file_name, F_OK) == 0) {
if (archive->backup_type == no_backups) {
- if (wy_debug_level)
- logmsg(LOG_DEBUG,
- _("removing previous archive "
- "file `%s'"),
- file_name);
+ wy_debug(1, (_("removing previous archive "
+ "file `%s'"),
+ file_name));
if (!dry_run_mode && unlink(file_name)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot unlink previous archive "
"file `%s': %s"),
file_name, strerror(errno));
@@ -304,16 +301,14 @@ backup_file(const char *dst_file, const char *dst_dir, const char *file,
char *archive_file_name =
find_backup_file_name(file_name,
archive->backup_type);
- if (wy_debug_level)
- logmsg(LOG_DEBUG,
- _("backing up previous archive "
- "file `%s' to `%s'"),
- file_name, archive_file_name);
+ wy_debug(1, (_("backing up previous archive "
+ "file `%s' to `%s'"),
+ file_name, archive_file_name));
if (!dry_run_mode) {
rc = do_move_file(file_name,
archive_file_name);
if (rc) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("backing `%s' up as `%s' failed: %s"),
file_name, archive_file_name,
strerror(errno));
@@ -327,13 +322,11 @@ backup_file(const char *dst_file, const char *dst_dir, const char *file,
}
}
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("archiving `%s' to `%s'"), dst_file,
- file_name);
+ wy_debug(1, (_("archiving `%s' to `%s'"), dst_file, file_name));
if (!dry_run_mode) {
rc = do_move_file(dst_file, file_name);
if (rc)
- logmsg(LOG_ERR, _("archiving `%s' as `%s' failed: %s"),
+ wy_log(LOG_ERR, _("archiving `%s' as `%s' failed: %s"),
dst_file, file_name, strerror(errno));
}
free(file_name);
@@ -365,7 +358,7 @@ do_archive_file(const char *dst_file, const char *dst_dir, const char *file,
}
if (!dry_run_mode && unlink(dst_file) && errno != ENOENT) {
- logmsg(LOG_ERR, _("canot unlink file `%s': %s"),
+ wy_log(LOG_ERR, _("canot unlink file `%s': %s"),
dst_file, strerror(errno));
return 1;
}
@@ -408,9 +401,8 @@ dir_move_file(struct file_triplet *trp, enum file_type file_id)
return 1;
dst_file = concat_dir(dst_dir, trp->file[file_id].name, NULL);
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("installing %s to %s"),
- trp->file[file_id].name, dst_dir);
+ wy_debug(1, (_("installing %s to %s"),
+ trp->file[file_id].name, dst_dir));
if (access(dst_file, F_OK) == 0) {
if (replace_allowed_p(trp))
@@ -419,7 +411,7 @@ dir_move_file(struct file_triplet *trp, enum file_type file_id)
&spool->archive,
trp->relative_dir);
else {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("refusing to upload %s because it already "
"exists and replace is not allowed"),
trp->file[file_id].name);
@@ -457,7 +449,7 @@ archive_single_file(struct file_triplet *trp, const char *file_name,
dst_file = safe_file_name(concat_dir(dst_dir, file_name, NULL));
if (!sub_dir_p(dst_file, spool->dest_dir)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("file to be archived `%s' does not lie under `%s'"),
dst_file, spool->dest_dir);
free(dst_file);
@@ -466,18 +458,17 @@ archive_single_file(struct file_triplet *trp, const char *file_name,
}
if (access(dst_file, F_OK) == 0) {
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("archiving file `%s'"), dst_file);
+ wy_debug(1, (_("archiving file `%s'"), dst_file));
rc = do_archive_file(dst_file, dst_dir, file_name,
&spool->archive, trp->relative_dir);
} else if (errno == ENOENT) {
if (!noentok)
- logmsg(LOG_NOTICE,
+ wy_log(LOG_NOTICE,
_("nothing to archive: "
"file `%s' does not exist"),
dst_file);
} else {
- logmsg(LOG_ERR, _("canot access file `%s': %s"),
+ wy_log(LOG_ERR, _("canot access file `%s': %s"),
dst_file, strerror(errno));
rc = 1;
}
@@ -539,7 +530,7 @@ dir_symlink_file(struct file_triplet *trp,
src = safe_file_name_alloc(wanted_src);
if (!src || src[0] == '/') {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("symlink source `%s' does not lie under `%s'"),
wanted_src, spool->dest_dir);
free(src);
@@ -548,7 +539,7 @@ dir_symlink_file(struct file_triplet *trp,
dst = safe_file_name_alloc(wanted_dst);
if (!dst || dst[0] == '/') {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("symlink destination `%s' does not lie under `%s'"),
wanted_dst, spool->dest_dir);
free(src);
@@ -556,9 +547,8 @@ dir_symlink_file(struct file_triplet *trp,
return 1;
}
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("symlinking %s to %s in directory %s"),
- src, dst, dst_dir);
+ wy_debug(1, (_("symlinking %s to %s in directory %s"),
+ src, dst, dst_dir));
if (!dry_run_mode) {
char *p = strrchr(dst, '/');
@@ -576,25 +566,25 @@ dir_symlink_file(struct file_triplet *trp,
if (rc == 0) {
if (push_dir(dst_dir))
- logmsg(LOG_ERR, _("cannot change to %s: %s"),
+ wy_log(LOG_ERR, _("cannot change to %s: %s"),
dst_dir, strerror(errno));
else {
struct stat st;
if (lstat(dst, &st) == 0) {
if (!S_ISLNK(st.st_mode)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("file %s exists and is not a symbolic link"),
dst);
rc = 1;
} else if (unlink(dst)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot unlink %s: %s"),
dst, strerror(errno));
rc = 1;
}
} else if (errno != ENOENT) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot stat file %s: %s"),
dst, strerror(errno));
rc = 1;
@@ -603,13 +593,13 @@ dir_symlink_file(struct file_triplet *trp,
if (rc == 0) {
rc = symlink(src, dst);
if (rc)
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("symlinking %s to %s in directory %s failed: %s"),
src, dst, dst_dir,
strerror(errno));
}
if (pop_dir()) {
- logmsg(LOG_EMERG,
+ wy_log(LOG_EMERG,
_("cannot restore current directory: %s"),
strerror(errno));
exit(EX_SOFTWARE);
@@ -632,26 +622,25 @@ do_rmsymlink_file(const char *dst_file, int noentok)
{
struct stat st;
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("removing symbolic link %s"), dst_file);
+ wy_debug(1, (_("removing symbolic link %s"), dst_file));
if (stat(dst_file, &st)) {
if (errno == ENOENT) {
if (!noentok)
- logmsg(LOG_NOTICE,
+ wy_log(LOG_NOTICE,
_("symlink `%s' does not exist"),
dst_file);
return 0;
}
if (!S_ISLNK(st.st_mode)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("refusing to unlink %s: is not a symlink"),
dst_file);
return 1;
}
}
if (!dry_run_mode && unlink(dst_file)) {
- logmsg(LOG_ERR, _("cannot unlink %s: %s"), dst_file,
+ wy_log(LOG_ERR, _("cannot unlink %s: %s"), dst_file,
strerror(errno));
return 1;
}
@@ -676,7 +665,7 @@ dir_rmsymlink_file(struct file_triplet *trp, const char *file_name)
dst_file = safe_file_name(concat_dir(dst_dir, file_name, NULL));
if (!sub_dir_p(dst_file, spool->dest_dir)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("refusing to remove a symlink `%s' that is not "
"located under `%s'"), dst_file, spool->dest_dir);
free(dst_file);

Return to:

Send suggestions and report system problems to the System administrator.