From 389ea5d8063b01d3bdbed117e7da7f80e312bc88 Mon Sep 17 00:00:00 2001 From: "Alexander V. Lukyanov" Date: Fri, 8 Jul 2016 10:59:48 +0300 Subject: [PATCH] GetJob: apply noclobber setting to plain files only. --- NEWS | 1 + src/GetJob.cc | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/GetJob.cc b/src/GetJob.cc index 7afba0a..683b666 100644 --- a/src/GetJob.cc +++ b/src/GetJob.cc @@ -65,24 +65,25 @@ FileCopyPeer *GetJob::SrcLocal(const char *src) FileCopyPeer *GetJob::DstLocal(const char *dst) { bool clobber=(cont || QueryBool("xfer:clobber",0)); - int flags=O_WRONLY|O_CREAT|(truncate_target_first?O_TRUNC:0)|(clobber?0:O_EXCL); + int flags=O_WRONLY|O_CREAT|(truncate_target_first?O_TRUNC:0); dst=expand_home_relative(dst); const char *f=(cwd && dst[0]!='/') ? dir_file(cwd,dst) : dst; - if(truncate_target_first && QueryBool("xfer:make-backup",0)) + + struct stat st; + if(stat(f,&st)!=-1) { - /* rename old file if exists and size>0 */ - struct stat st; - if(stat(f,&st)!=-1) + if(st.st_size>0 && S_ISREG(st.st_mode)) { - if(st.st_size>0 && S_ISREG(st.st_mode)) + if(!clobber) + { + eprintf(_("%s: %s: file already exists and xfer:clobber is unset\n"),op,dst); + errors++; + count++; + return 0; + } + if(truncate_target_first && QueryBool("xfer:make-backup",0)) { - if(!clobber) - { - eprintf(_("%s: %s: file already exists and xfer:clobber is unset\n"),op,dst); - errors++; - count++; - return 0; - } + /* rename old file if exists and size>0 */ xstring_ca suffix(xstrftime(Query("xfer:backup-suffix",0),now)); backup_file.set(f).append(suffix); if(rename(f,backup_file)!=0)