diff options
author | Marc Laukien <marc@zeroc.com> | 2002-04-04 22:02:41 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2002-04-04 22:02:41 +0000 |
commit | 60b2933943fe4c08011182df28c96829e2d99b67 (patch) | |
tree | 9e6943073035fac497e0dd0ad04e8231aeda1374 /cpp/src | |
parent | more IcePatch stuff (diff) | |
download | ice-60b2933943fe4c08011182df28c96829e2d99b67.tar.bz2 ice-60b2933943fe4c08011182df28c96829e2d99b67.tar.xz ice-60b2933943fe4c08011182df28c96829e2d99b67.zip |
more IcePatch stuff
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/IcePatch/Client.cpp | 29 | ||||
-rw-r--r-- | cpp/src/IcePatch/NodeI.cpp | 4 | ||||
-rw-r--r-- | cpp/src/IcePatch/NodeI.h | 2 | ||||
-rw-r--r-- | cpp/src/IcePatch/Util.cpp | 48 |
4 files changed, 60 insertions, 23 deletions
diff --git a/cpp/src/IcePatch/Client.cpp b/cpp/src/IcePatch/Client.cpp index 1b1c2cb3e7a..5fdda3c010d 100644 --- a/cpp/src/IcePatch/Client.cpp +++ b/cpp/src/IcePatch/Client.cpp @@ -26,6 +26,7 @@ public: void usage(); virtual int run(int, char*[]); void printNodeDescSeq(const NodeDescSeq&, const string&); + void getFile(const FilePrx&); }; }; @@ -211,6 +212,8 @@ IcePatch::Client::printNodeDescSeq(const NodeDescSeq& nodeDescSeq, const string& { case FileInfoNotExist: { + cout << "getting file... " << flush; + getFile(fileDesc->file); break; } @@ -218,11 +221,21 @@ IcePatch::Client::printNodeDescSeq(const NodeDescSeq& nodeDescSeq, const string& { cout << "removing directory... " << flush; removeRecursive(path); + cout << "getting file... " << flush; + getFile(fileDesc->file); break; } case FileInfoRegular: { + ByteSeq md5 = getMD5(path); + if (md5 != fileDesc->md5) + { + cout << "removing file... " << flush; + removeRecursive(path); + cout << "getting file... " << flush; + getFile(fileDesc->file); + } break; } @@ -230,6 +243,8 @@ IcePatch::Client::printNodeDescSeq(const NodeDescSeq& nodeDescSeq, const string& { cout << "removing unknown file... " << flush; removeRecursive(path); + cout << "getting file... " << flush; + getFile(fileDesc->file); break; } } @@ -244,6 +259,20 @@ IcePatch::Client::printNodeDescSeq(const NodeDescSeq& nodeDescSeq, const string& } } +void +IcePatch::Client::getFile(const FilePrx& file) +{ + ByteSeq bytes; + Int pos = 0; + + do + { + bytes = file->getBytesBZ2(pos, 256 * 1024); + pos += bytes.size(); + } + while (!bytes.empty()); +} + int main(int argc, char* argv[]) { diff --git a/cpp/src/IcePatch/NodeI.cpp b/cpp/src/IcePatch/NodeI.cpp index 575bb980e7e..abbc06b0cd4 100644 --- a/cpp/src/IcePatch/NodeI.cpp +++ b/cpp/src/IcePatch/NodeI.cpp @@ -82,7 +82,7 @@ IcePatch::FileI::describe(const Ice::Current& current) } ByteSeq -IcePatch::FileI::getBlock(Int n, const Ice::Current& current) +IcePatch::FileI::getBytesBZ2(Ice::Int pos, Ice::Int num, const Ice::Current& current) { - return getBlockBZ2(identityToPath(current.identity), n); + return IcePatch::getBytesBZ2(identityToPath(current.identity), pos, num); } diff --git a/cpp/src/IcePatch/NodeI.h b/cpp/src/IcePatch/NodeI.h index d64166c1856..93e7db2d6be 100644 --- a/cpp/src/IcePatch/NodeI.h +++ b/cpp/src/IcePatch/NodeI.h @@ -47,7 +47,7 @@ public: FileI(const Ice::ObjectAdapterPtr&); virtual NodeDescPtr describe(const Ice::Current&); - virtual Ice::ByteSeq getBlock(Ice::Int, const Ice::Current&); + virtual Ice::ByteSeq getBytesBZ2(Ice::Int, Ice::Int, const Ice::Current&); }; } diff --git a/cpp/src/IcePatch/Util.cpp b/cpp/src/IcePatch/Util.cpp index c1bacee3fbf..9e344fd4421 100644 --- a/cpp/src/IcePatch/Util.cpp +++ b/cpp/src/IcePatch/Util.cpp @@ -475,7 +475,7 @@ createBZ2(const string& path, char* buf, int sz) } ByteSeq -IcePatch::getBlockBZ2(const string& path, Int n) +IcePatch::getBytesBZ2(const string& path, Int pos, Int num) { // // Stat the file to get a bzip2 file for. @@ -532,7 +532,6 @@ IcePatch::getBlockBZ2(const string& path, Int n) } } -/* if (createbz2) { // @@ -547,7 +546,7 @@ IcePatch::getBlockBZ2(const string& path, Int n) throw ex; } - unsigned char* fileBuf = new unsigned char[buf.st_size]; + char* fileBuf = new char[buf.st_size]; try { @@ -578,13 +577,23 @@ IcePatch::getBlockBZ2(const string& path, Int n) delete [] fileBuf; throw; } - } + +/* + // + // Stat the .bz2 file. This time, it must exist. + // + if (::stat(pathbz2.c_str(), &bufbz2) == -1) + { + NodeAccessException ex; + ex.reason = "cannot stat `" + path + "':" + strerror(errno); + throw ex; + } */ + } // - // Open the bzip2 file and read the appropriate block of data. + // Open and read the bzip2 file. // - pathbz2 = path; int fd = ::open(pathbz2.c_str(), O_RDONLY); if (fd == -1) @@ -593,23 +602,22 @@ IcePatch::getBlockBZ2(const string& path, Int n) ex.reason = "cannot open `" + pathbz2 + "' for reading:" + strerror(errno); throw ex; } - - ByteSeq block; - block.resize(128); // TODO: This is a very small number for testing only. + + ByteSeq bytes; + bytes.resize(num); try { - off_t offset = lseek(fd, n * block.size(), SEEK_SET); - if (offset == -1) + if (lseek(fd, pos, SEEK_SET) == -1) { NodeAccessException ex; ostringstream out; - out << "cannot seek position " << n * block.size() << " in file `" + pathbz2 + "':" + strerror(errno); + out << "cannot seek position " << pos << " in file `" << path << "':" << strerror(errno); ex.reason = out.str(); throw ex; } - - int sz = ::read(fd, &block[0], block.size()); + + int sz = ::read(fd, &bytes[0], num); if (sz == -1) { @@ -617,16 +625,16 @@ IcePatch::getBlockBZ2(const string& path, Int n) ex.reason = "cannot read `" + path + "':" + strerror(errno); throw ex; } - - block.resize(sz); - - close(fd); + + bytes.resize(sz); + + ::close(fd); } catch (...) { - close(fd); + ::close(fd); throw; } - return block; + return bytes; } |