diff options
author | Marc Laukien <marc@zeroc.com> | 2002-09-05 15:48:46 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2002-09-05 15:48:46 +0000 |
commit | 22a89af145cfe3fd5fe9817ddd36c0191563cc67 (patch) | |
tree | 9d94fefa6080f0b4d81688a5617ee5a5302cbce9 /cpp/src/IcePatch/Util.cpp | |
parent | fixes (diff) | |
download | ice-22a89af145cfe3fd5fe9817ddd36c0191563cc67.tar.bz2 ice-22a89af145cfe3fd5fe9817ddd36c0191563cc67.tar.xz ice-22a89af145cfe3fd5fe9817ddd36c0191563cc67.zip |
more icepatch work
Diffstat (limited to 'cpp/src/IcePatch/Util.cpp')
-rw-r--r-- | cpp/src/IcePatch/Util.cpp | 154 |
1 files changed, 46 insertions, 108 deletions
diff --git a/cpp/src/IcePatch/Util.cpp b/cpp/src/IcePatch/Util.cpp index 2906620819f..42b1d419042 100644 --- a/cpp/src/IcePatch/Util.cpp +++ b/cpp/src/IcePatch/Util.cpp @@ -324,46 +324,66 @@ IcePatch::getMD5(const string& path) void IcePatch::createMD5(const string& path) { - FileInfo info = getFileInfo(path, true); - if(info.type == FileTypeDirectory) - { - FileAccessException ex; - ex.reason = "cannot create MD5 file for `" + path + "' because this is a directory"; - throw ex; - } - // - // Read the original file. + // The current directory is not permissible for MD5 value + // creation. // - ifstream file(path.c_str(), ios::binary); - if(!file) + assert(path != "."); + + ByteSeq bytes; + + FileInfo info = getFileInfo(path, true); + if(info.type == FileTypeDirectory) { - FileAccessException ex; - ex.reason = "cannot open `" + path + "' for reading: " + strerror(errno); - throw ex; + // + // Create a summary of all MD5 files. + // + StringSeq paths = readDirectory(path); + for(StringSeq::const_iterator p = paths.begin(); p < paths.end(); ++p) + { + if(getSuffix(*p) == "md5") + { + ByteSeq subBytesMD5 = getMD5(removeSuffix(*p)); + copy(subBytesMD5.begin(), subBytesMD5.end(), back_inserter(bytes)); + } + } } - - ByteSeq bytes; - bytes.resize(info.size); - if(bytes.size() > 0) + else { - file.read(&bytes[0], bytes.size()); + assert(info.type == FileTypeRegular); + + // + // Read the original file. + // + ifstream file(path.c_str(), ios::binary); if(!file) { FileAccessException ex; - ex.reason = "cannot read `" + path + "': " + strerror(errno); + ex.reason = "cannot open `" + path + "' for reading: " + strerror(errno); throw ex; } - if(file.gcount() < static_cast<int>(bytes.size())) + + bytes.resize(info.size); + if(bytes.size() > 0) { - FileAccessException ex; - ex.reason = "could not read all bytes from `" + path + "'"; - throw ex; + file.read(&bytes[0], bytes.size()); + if(!file) + { + FileAccessException ex; + ex.reason = "cannot read `" + path + "': " + strerror(errno); + throw ex; + } + if(file.gcount() < static_cast<int>(bytes.size())) + { + FileAccessException ex; + ex.reason = "could not read all bytes from `" + path + "'"; + throw ex; + } } + + file.close(); } - file.close(); - // // Create the MD5 hash value. // @@ -652,85 +672,3 @@ IcePatch::createBZ2(const string& path) throw ex; } } - -Long -IcePatch::readStamp() -{ - ifstream fileStamp(".icepatch/stamp"); - if(!fileStamp) // Ignore any errors if the file cannot be read. - { - return -1; - } - - string s; - fileStamp >> s; - fileStamp.close(); - - Long stamp; - string::size_type dummy; - if(!IceUtil::stringToInt64(s, stamp, dummy)) // Ignore errors during conversion. - { - return -1; - } - - return stamp; -} - -void -IcePatch::writeStamp(Long stamp) -{ - ofstream fileStamp(".icepatch/stamp"); - if(!fileStamp) - { - // - // Prepare an exception, but don't throw yet. - // - FileAccessException ex; - ex.reason = string("cannot open `.icepatch/stamp' for writing: ") + strerror(errno); - - // - // Check if the directory exists, and only throw the exception - // if it does exist. Otherwise create the directory, and try - // again. - // - FileInfo info = getFileInfo(".icepatch", false); - if(info.type == FileTypeDirectory) - { - // - // If the directory exists, throw the exception. - // - throw ex; - } - else - { - // - // If the directory does not exist, create it, and try - // again. - // - if(info.type != FileTypeNotExist) - { - removeRecursive(".icepatch"); - } - - createDirectory(".icepatch"); - - ofstream fileStamp(".icepatch/stamp"); - if(!fileStamp) - { - FileAccessException ex; - ex.reason = string("cannot open `.icepatch/stamp' for writing: ") + strerror(errno); - throw ex; - } - else - { - fileStamp << stamp << endl; - fileStamp.close(); - } - } - } - else - { - fileStamp << stamp << endl; - fileStamp.close(); - } -} |