mirror of https://github.com/odrling/Aegisub
Only check for permissions if opening a file fails
This commit is contained in:
parent
ac5f40a543
commit
d08f4e73b4
|
@ -32,12 +32,12 @@ namespace agi {
|
|||
|
||||
std::unique_ptr<std::istream> Open(fs::path const& file, bool binary) {
|
||||
LOG_D("agi/io/open/file") << file;
|
||||
acs::CheckFileRead(file);
|
||||
|
||||
auto stream = agi::make_unique<boost::filesystem::ifstream>(file, (binary ? std::ios::binary : std::ios::in));
|
||||
|
||||
if (stream->fail())
|
||||
throw IOFatal("Unknown fatal error as occurred");
|
||||
if (stream->fail()) {
|
||||
acs::CheckFileRead(file);
|
||||
throw IOFatal("Unknown fatal error occurred opening " + file.string());
|
||||
}
|
||||
|
||||
return std::unique_ptr<std::istream>(stream.release());
|
||||
}
|
||||
|
@ -47,19 +47,14 @@ Save::Save(fs::path const& file, bool binary)
|
|||
, tmp_name(unique_path(file.parent_path()/(file.stem().string() + "_tmp_%%%%" + file.extension().string())))
|
||||
{
|
||||
LOG_D("agi/io/save/file") << file;
|
||||
acs::CheckDirWrite(file.parent_path());
|
||||
|
||||
try {
|
||||
acs::CheckFileWrite(file);
|
||||
}
|
||||
catch (fs::FileNotFound const&) {
|
||||
// Not an error
|
||||
}
|
||||
|
||||
fp = agi::make_unique<boost::filesystem::ofstream>(tmp_name, binary ? std::ios::binary : std::ios::out);
|
||||
if (!fp->good())
|
||||
if (!fp->good()) {
|
||||
acs::CheckDirWrite(file.parent_path());
|
||||
acs::CheckFileWrite(file);
|
||||
throw fs::WriteDenied(tmp_name);
|
||||
}
|
||||
}
|
||||
|
||||
Save::~Save() {
|
||||
fp.reset(); // Need to close before rename on Windows to unlock the file
|
||||
|
|
Loading…
Reference in New Issue