diff options
author | Mike Miller <mtmiller@ieee.org> | 2016-12-25 09:38:04 +0800 |
---|---|---|
committer | Mike Miller <mtmiller@debian.org> | 2016-12-25 09:38:04 +0800 |
commit | 764f026336d13640db9f1fd6c1173cbebe0c4314 (patch) | |
tree | 9536dcc751b18d2e9e4a9e1de9d8f273b580d1e2 | |
parent | 4e6c59f9059c0c0a14d9adeba8d4db3d5fdff97c (diff) |
Check for existence of ~/.cdargs before making a backup copy
Forwarded: no
Bug-Debian: https://bugs.debian.org/713007
Last-Update: 2013-10-30
Gbp-Pq: Name 09_avoid_backupfile_warning.patch
-rw-r--r-- | src/cdargs.cc | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/cdargs.cc b/src/cdargs.cc index b8df568..d3fb383 100644 --- a/src/cdargs.cc +++ b/src/cdargs.cc @@ -728,9 +728,12 @@ void list_to_file(void) { if(opt_user.size() > 0) { return; } - string backup_file = mylistfile + "~"; - if(rename(mylistfile.c_str(),backup_file.c_str()) == -1) { - fprintf(stderr,"warning: could not create backupfile\n"); + struct stat buf; + if(stat(mylistfile.c_str(),&buf) == 0) { + string backup_file = mylistfile + "~"; + if(rename(mylistfile.c_str(),backup_file.c_str()) == -1) { + fprintf(stderr,"warning: could not create backupfile\n"); + } } ofstream listfile(mylistfile.c_str()); if (!listfile) { |