Skip to content

Commit 5f1f115

Browse files
selatsapier
selat
authored and
sapier
committedAug 16, 2014
Remove temporary file at safeWriteToFile()
1 parent f6e01ad commit 5f1f115

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed
 

‎src/filesys.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -701,16 +701,19 @@ bool safeWriteToFile(const std::string &path, const std::string &content)
701701
os << content;
702702
os.flush();
703703
os.close();
704-
if (os.fail())
704+
if (os.fail()) {
705+
remove(tmp_file.c_str());
705706
return false;
707+
}
706708

707709
// Copy file
708-
#ifdef _WIN32
709710
remove(path.c_str());
710-
return (rename(tmp_file.c_str(), path.c_str()) == 0);
711-
#else
712-
return (rename(tmp_file.c_str(), path.c_str()) == 0);
713-
#endif
711+
if(rename(tmp_file.c_str(), path.c_str())) {
712+
remove(tmp_file.c_str());
713+
return false;
714+
} else {
715+
return true;
716+
}
714717
}
715718

716719
} // namespace fs

0 commit comments

Comments
 (0)
Please sign in to comment.