diff options
Diffstat (limited to 'src/diskio.c')
-rw-r--r-- | src/diskio.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/diskio.c b/src/diskio.c index 2e61d49..bab5cb8 100644 --- a/src/diskio.c +++ b/src/diskio.c @@ -1,5 +1,5 @@ /* wydawca - automatic release submission daemon - Copyright (C) 2007-2011 Sergey Poznyakoff + Copyright (C) 2007-2012 Sergey Poznyakoff Wydawca is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -398,6 +398,19 @@ do_archive_file (const char *dst_file, const char *dst_dir, const char *file, return 0; } +static int +replace_allowed_p (struct file_triplet *trp) +{ + const char *val; + + if (trp->version < 102) + return 1; + + if (directive_get_value (trp, "replace", &val)) + return 1; + return strcmp (val, "true") == 0; +} + /* Move the part FILE_ID of the triplet TRP between the directories in TRP->SPOOL. TRP->RELATIVE_DIR gives relative directory (i.e. the directory part of the file name) for backup purposes. @@ -420,8 +433,21 @@ dir_move_file (struct file_triplet *trp, enum file_type file_id) dst_dir); if (access (dst_file, F_OK) == 0) - rc = do_archive_file (dst_file, dst_dir, trp->file[file_id].name, - &spool->archive, trp->relative_dir); + { + if (replace_allowed_p (trp)) + rc = do_archive_file (dst_file, dst_dir, trp->file[file_id].name, + &spool->archive, trp->relative_dir); + else + { + logmsg (LOG_ERR, + _("refusing to upload %s because it already exists " + "and replace is not allowed"), + trp->file[file_id].name); + free (dst_file); + free (dst_dir); + return 1; + } + } if (!dry_run_mode && rc == 0) rc = do_move_file (trp->file[file_id].name, dst_file); |