fs/FileSystem: RemoveFile() throws exception on error
This commit is contained in:
@@ -66,3 +66,15 @@ TruncateFile(Path path)
|
||||
close(fd);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
RemoveFile(Path path)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if (!DeleteFile(path.c_str()))
|
||||
throw FormatLastError("Failed to delete %s", path.c_str());
|
||||
#else
|
||||
if (unlink(path.c_str()) < 0)
|
||||
throw FormatErrno("Failed to delete %s", path.c_str());
|
||||
#endif
|
||||
}
|
||||
|
@@ -100,17 +100,11 @@ void
|
||||
TruncateFile(Path path);
|
||||
|
||||
/**
|
||||
* Wrapper for unlink() that uses #Path names.
|
||||
* Wrapper for unlink() that uses #Path names. Throws
|
||||
* std::system_error on error.
|
||||
*/
|
||||
static inline bool
|
||||
RemoveFile(Path file)
|
||||
{
|
||||
#ifdef WIN32
|
||||
return _tunlink(file.c_str()) == 0;
|
||||
#else
|
||||
return unlink(file.c_str()) == 0;
|
||||
#endif
|
||||
}
|
||||
void
|
||||
RemoveFile(Path path);
|
||||
|
||||
/**
|
||||
* Wrapper for readlink() that uses #Path names.
|
||||
|
@@ -76,7 +76,11 @@ FileOutputStream::Cancel()
|
||||
assert(IsDefined());
|
||||
|
||||
Close();
|
||||
RemoveFile(GetPath());
|
||||
|
||||
try {
|
||||
RemoveFile(GetPath());
|
||||
} catch (std::runtime_error) {
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -153,7 +157,10 @@ FileOutputStream::Commit()
|
||||
|
||||
#if HAVE_LINKAT
|
||||
if (is_tmpfile) {
|
||||
RemoveFile(GetPath());
|
||||
try {
|
||||
RemoveFile(GetPath());
|
||||
} catch (std::runtime_error) {
|
||||
}
|
||||
|
||||
/* hard-link the temporary file to the final path */
|
||||
char fd_path[64];
|
||||
@@ -186,7 +193,10 @@ FileOutputStream::Cancel()
|
||||
#ifdef HAVE_LINKAT
|
||||
if (!is_tmpfile)
|
||||
#endif
|
||||
RemoveFile(GetPath());
|
||||
try {
|
||||
RemoveFile(GetPath());
|
||||
} catch (std::runtime_error) {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user