From d08f4e73b4fde3e54cf7caa5dc8476f004084ea0 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 26 May 2014 19:37:40 -0700 Subject: [PATCH] Only check for permissions if opening a file fails --- libaegisub/common/io.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/libaegisub/common/io.cpp b/libaegisub/common/io.cpp index c95c5559a..c8531120f 100644 --- a/libaegisub/common/io.cpp +++ b/libaegisub/common/io.cpp @@ -32,12 +32,12 @@ namespace agi { std::unique_ptr Open(fs::path const& file, bool binary) { LOG_D("agi/io/open/file") << file; - acs::CheckFileRead(file); auto stream = agi::make_unique(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(stream.release()); } @@ -47,18 +47,13 @@ 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(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() {