rendered paste bodyIndex: File.cpp
===================================================================
RCS file: /cvsroot/linuxdcpp/linuxdcpp/client/File.cpp,v
retrieving revision 1.4
diff -u -r1.4 File.cpp
--- File.cpp 7 Jul 2007 21:21:06 -0000 1.4
+++ File.cpp 7 Oct 2007 19:17:59 -0000
@@ -223,8 +223,9 @@
}
h = open(filename.c_str(), m, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
- if(h == -1)
- throw FileException("Could not open file");
+ if(h == -1) {
+ throw FileException("Could not open file: "+Util::translateError(errno));
+ }
}
uint32_t File::getLastModified() throw() {
@@ -271,20 +272,22 @@
}
size_t File::read(void* buf, size_t& len) throw(FileException) {
- ssize_t x = ::read(h, buf, len);
- if(x == -1)
- throw FileException("Read error");
- len = x;
- return (size_t)x;
+ ssize_t result = ::read(h, buf, len);
+ if (result == -1) {
+ throw FileException("Read error: "+Util::translateError(errno));
+ }
+ len = result;
+ return (size_t)result;
}
size_t File::write(const void* buf, size_t len) throw(FileException) {
- ssize_t x = ::write(h, buf, len);
- if(x == -1)
- throw FileException("Write error");
- if(x < (ssize_t)len)
- throw FileException("Disk full(?)");
- return x;
+ ssize_t result = ::write(h, buf, len);
+
+ if (result == -1) {
+ throw FileException("Write error: "+Util::translateError(errno));
+ }
+
+ return result;
}
// some ftruncate implementations can't extend files like SetEndOfFile,
@@ -338,10 +341,10 @@
void File::renameFile(const string& source, const string& target) throw(FileException) {
int ret = ::rename(Text::fromUtf8(source).c_str(), Text::fromUtf8(target).c_str());
if(ret != 0 && errno == EXDEV) {
- copyFile(source.c_str(), target.c_str());
- deleteFile(source.c_str());
+ copyFile(source, target);
+ deleteFile(source);
} else if(ret != 0)
- throw FileException(source.c_str() + Util::translateError(errno));
+ throw FileException(source + Util::translateError(errno));
}
// This doesn't assume all bytes are written in one write call, it is a bit safer