summaryrefslogtreecommitdiff
path: root/cpp/src/IcePatch/Util.cpp
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2002-09-01 21:21:05 +0000
committerMarc Laukien <marc@zeroc.com>2002-09-01 21:21:05 +0000
commit31b064d4e4f55aadb9f03ab66ac59a94d82adfb6 (patch)
treec9e86b395f9c2c45e8205ae8ab99d3c5cbe6b838 /cpp/src/IcePatch/Util.cpp
parentcleaning up empty identity handling (diff)
downloadice-31b064d4e4f55aadb9f03ab66ac59a94d82adfb6.tar.bz2
ice-31b064d4e4f55aadb9f03ab66ac59a94d82adfb6.tar.xz
ice-31b064d4e4f55aadb9f03ab66ac59a94d82adfb6.zip
IcePatch work
Diffstat (limited to 'cpp/src/IcePatch/Util.cpp')
-rw-r--r--cpp/src/IcePatch/Util.cpp82
1 files changed, 65 insertions, 17 deletions
diff --git a/cpp/src/IcePatch/Util.cpp b/cpp/src/IcePatch/Util.cpp
index 4130c14b0f7..82d33275f09 100644
--- a/cpp/src/IcePatch/Util.cpp
+++ b/cpp/src/IcePatch/Util.cpp
@@ -70,6 +70,11 @@ normalizePath(const string& path)
result.erase(0, 2);
}
+ if(result.size() >= 2 && result.substr(result.size() - 2, 2) == "/.")
+ {
+ result.erase(result.size() - 2, 2);
+ }
+
return result;
}
@@ -205,6 +210,7 @@ IcePatch::readDirectory(const string& path)
while(true)
{
string name = data.name;
+ assert(!name.empty());
if(name != ".." && name != ".")
{
@@ -248,6 +254,7 @@ IcePatch::readDirectory(const string& path)
for(int i = 0; i < n; ++i)
{
string name = namelist[i]->d_name;
+ assert(!name.empty());
free(namelist[i]);
@@ -360,33 +367,60 @@ IcePatch::getPartialMD5(const string& path, Int size)
void
IcePatch::createMD5(const string& path)
{
- //
- // Read the original file.
- //
FileInfo info = getFileInfo(path, true);
- ifstream file(path.c_str(), ios::binary);
- if(!file)
+ if(info.type == FileTypeUnknown)
{
FileAccessException ex;
- ex.reason = "cannot open `" + path + "' for reading: " + strerror(errno);
+ ex.reason = "cannot create .md5 file for `" + path + "' because file type is unknown";
throw ex;
}
+
ByteSeq bytes;
- bytes.resize(info.size);
- file.read(&bytes[0], bytes.size());
- if(!file)
+ if(info.type == FileTypeDirectory)
{
- FileAccessException ex;
- ex.reason = "cannot read `" + path + "': " + strerror(errno);
- throw ex;
+ //
+ // Read all MD5 files in the directory.
+ //
+ StringSeq paths = readDirectory(path);
+ for(StringSeq::const_iterator p = paths.begin(); p != paths.end(); ++p)
+ {
+ if(getSuffix(*p) == "md5")
+ {
+ ByteSeq md5 = getMD5(removeSuffix(*p));
+ copy(md5.begin(), md5.end(), back_inserter(bytes));
+ }
+ }
}
- if(file.gcount() < static_cast<int>(bytes.size()))
+ else
{
- FileAccessException ex;
- ex.reason = "could not read all bytes from `" + path + "'";
- throw ex;
+ assert(info.type == FileTypeRegular);
+
+ //
+ // Read the original file.
+ //
+ ifstream file(path.c_str(), ios::binary);
+ if(!file)
+ {
+ FileAccessException ex;
+ ex.reason = "cannot open `" + path + "' for reading: " + strerror(errno);
+ throw ex;
+ }
+ bytes.resize(info.size);
+ 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.
@@ -488,6 +522,20 @@ IcePatch::getBZ2(const string& path, Int pos, Int num)
void
IcePatch::createBZ2(const string& path)
{
+ FileInfo info = getFileInfo(path, true);
+ if(info.type == FileTypeUnknown)
+ {
+ FileAccessException ex;
+ ex.reason = "cannot create .bz2 file for `" + path + "' because file type is unknown";
+ throw ex;
+ }
+ if(info.type == FileTypeDirectory)
+ {
+ FileAccessException ex;
+ ex.reason = "cannot create .bz2 file for `" + path + "' because this is a directory";
+ throw ex;
+ }
+
//
// Read the original file in blocks and write a temporary BZ2
// file.