2010-10-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Rewritten AbstractDiskWriter::openFile() without File::exists().
	* src/AbstractCommand.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-10-11 15:15:13 +00:00
parent 4ddc6eac58
commit 942f4c00a9
2 changed files with 19 additions and 12 deletions

View File

@ -1,3 +1,8 @@
2010-10-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten AbstractDiskWriter::openFile() without File::exists().
* src/AbstractCommand.cc
2010-10-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added errno member variable to Exception.

View File

@ -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());
}
}