* Added back up old files in 'save' before saving new data

git-svn-id: https://svn.code.sf.net/p/rathena/svn/branches/stable@1353 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
celest 2005-03-31 10:56:19 +00:00
parent c89903cdf1
commit 4109792003
2 changed files with 23 additions and 13 deletions

View File

@ -1,6 +1,10 @@
Date Added Date Added
03/31
* Added back up old files in 'save' before saving new data -- also fixes
'Access denied' errors when saving in TXT
03/30 03/30
* sql native vc7 projects now build/link [1351: MouseJstr] * sql native vc7 projects now build/link [1351: MouseJstr]
* Began sql projects for VC7 [1349: MouseJstr] * Began sql projects for VC7 [1349: MouseJstr]

View File

@ -2,8 +2,10 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "lock.h" #include "lock.h"
#include "showmsg.h" #include "showmsg.h"
#define exists(filename) (!access(filename, F_OK))
// 書き込みファイルの保護処理 // 書き込みファイルの保護処理
// (書き込みが終わるまで、旧ファイルを保管しておく) // (書き込みが終わるまで、旧ファイルを保管しておく)
@ -24,20 +26,24 @@ FILE* lock_fopen(const char* filename,int *info) {
// 旧ファイルを削除&新ファイルをリネーム // 旧ファイルを削除&新ファイルをリネーム
int lock_fclose (FILE *fp, const char* filename, int *info) { int lock_fclose (FILE *fp, const char* filename, int *info) {
int ret = 0; int ret = 1;
char newfile[512]; char newfile[512];
char oldfile[512];
if (fp != NULL) { if (fp != NULL) {
ret = fclose(fp); ret = fclose(fp);
sprintf(newfile, "%s_%04d.tmp", filename, *info); sprintf(newfile, "%s_%04d.tmp", filename, *info);
remove(filename); sprintf(oldfile, "%s.bak", filename); // old backup file
if (exists(oldfile)) remove(oldfile); // remove backup file if it already exists
rename (filename, oldfile); // backup our older data instead of deleting it
// このタイミングで落ちると最悪。 // このタイミングで落ちると最悪。
if (rename(newfile,filename) != 0) { if ((ret = rename(newfile,filename)) != 0) { // rename our temporary file to its correct name
sprintf(tmp_output,"%s - '"CL_WHITE"%s"CL_RESET"'\n", strerror(errno), newfile); sprintf(tmp_output,"%s - '"CL_WHITE"%s"CL_RESET"'\n", strerror(errno), newfile);
ShowError(tmp_output); ShowError(tmp_output);
} }
return ret; }
} else {
return 1; return ret;
}
} }