diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-10-11 15:15:13 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2010-10-11 15:15:13 +0000 |
| commit | 942f4c00a976a23316628135f3ae61546aa27415 (patch) | |
| tree | 061878d1a295e8a62ef0e7c45f4e5f98a3a6bbac /src/AbstractDiskWriter.cc | |
| parent | 4ddc6eac5820fc8ae21254fac68c890e9da5091d (diff) | |
2010-10-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten AbstractDiskWriter::openFile() without File::exists().
* src/AbstractCommand.cc
Diffstat (limited to 'src/AbstractDiskWriter.cc')
| -rw-r--r-- | src/AbstractDiskWriter.cc | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/AbstractDiskWriter.cc b/src/AbstractDiskWriter.cc index 1c4fdc1d..fd00d649 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()); } } |
