fix syncwritefile on windows

This commit is contained in:
cathugger 2022-06-24 18:08:51 +00:00
parent bd1b6d927e
commit f667a8a256
No known key found for this signature in database
GPG key ID: 9BADDA2DAF6F01A8
2 changed files with 10 additions and 2 deletions

View file

@ -22,6 +22,7 @@ mkdir -p out
SV=mkp224o-$V SV=mkp224o-$V
SO=$(realpath ./out/$SV) SO=$(realpath ./out/$SV)
git clone ../../ "$SO" git clone ../../ "$SO"
git -C ../../ diff | git -C "$SO" apply
cd "$SO" cd "$SO"
rm -rf .git rm -rf .git
./autogen.sh ./autogen.sh

View file

@ -221,22 +221,29 @@ int createdir(const char *path,int secret)
static int syncwritefile(const char *filename,const char *tmpname,int secret,const u8 *data,size_t datalen) static int syncwritefile(const char *filename,const char *tmpname,int secret,const u8 *data,size_t datalen)
{ {
FH f = createfile(tmpname,secret); FH f = createfile(tmpname,secret);
if (f == FH_invalid) if (f == FH_invalid) {
//fprintf(stderr,"!failed to create\n");
return -1; return -1;
}
if (writeall(f,data,datalen) < 0) { if (writeall(f,data,datalen) < 0) {
//fprintf(stderr,"!failed to write\n");
goto failclose; goto failclose;
} }
if (FlushFileBuffers(f) == 0) { if (FlushFileBuffers(f) == 0) {
//fprintf(stderr,"!failed to flush\n");
goto failclose; goto failclose;
} }
if (closefile(f) < 0) { if (closefile(f) < 0) {
//fprintf(stderr,"!failed to close\n");
goto failrm; goto failrm;
} }
if (MoveFileA(tmpname,filename) == 0) { if (MoveFileExA(tmpname,filename,MOVEFILE_REPLACE_EXISTING) == 0) {
//fprintf(stderr,"!failed to move\n");
goto failrm; goto failrm;
} }