diff --git a/ChangeLog b/ChangeLog index c7c5441a0..b5d5263a4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-10-12 Tatsuhiro Tsujikawa + + Rewritten AbstractDiskWriter::openFile() without File::exists(). + * src/AbstractCommand.cc + 2010-10-12 Tatsuhiro Tsujikawa Added errno member variable to Exception. diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index 1c4fdc1d9..fd00d6497 100644 --- a/src/AbstractDiskWriter.cc +++ b/src/AbstractDiskWriter.cc @@ -70,10 +70,14 @@ AbstractDiskWriter::~AbstractDiskWriter() void AbstractDiskWriter::openFile(uint64_t totalLength) { - if(File(filename_).exists()) { + try { openExistingFile(totalLength); - } else { - initAndOpenFile(totalLength); + } catch(RecoverableException& e) { + if(e.getErrno() == ENOENT) { + initAndOpenFile(totalLength); + } else { + throw; + } } } @@ -87,11 +91,6 @@ void AbstractDiskWriter::closeFile() void AbstractDiskWriter::openExistingFile(uint64_t totalLength) { - if(!File(filename_).exists()) { - throw DL_ABORT_EX - (StringFormat(EX_FILE_OPEN, filename_.c_str(), MSG_FILE_NOT_FOUND).str()); - } - int flags = O_BINARY; if(readOnly_) { flags |= O_RDONLY; @@ -100,8 +99,10 @@ void AbstractDiskWriter::openExistingFile(uint64_t totalLength) } if((fd_ = open(filename_.c_str(), flags, OPEN_MODE)) < 0) { - throw DL_ABORT_EX - (StringFormat(EX_FILE_OPEN, filename_.c_str(), strerror(errno)).str()); + throw DL_ABORT_EX2 + (errno, + StringFormat + (EX_FILE_OPEN, filename_.c_str(), strerror(errno)).str()); } } @@ -111,8 +112,9 @@ void AbstractDiskWriter::createFile(int addFlags) util::mkdirs(File(filename_).getDirname()); if((fd_ = open(filename_.c_str(), O_CREAT|O_RDWR|O_TRUNC|O_BINARY|addFlags, OPEN_MODE)) < 0) { - throw DL_ABORT_EX(StringFormat(EX_FILE_OPEN, - filename_.c_str(), strerror(errno)).str()); + throw DL_ABORT_EX2 + (errno, + StringFormat(EX_FILE_OPEN, filename_.c_str(), strerror(errno)).str()); } }