bool pkgAcqIndexDiffs::QueueNextDiff()
{
+
// calc sha1 of the just patched file
string FinalFile = _config->FindDir("Dir::State::lists");
FinalFile += URItoFileName(RealURI);
SHA1Summation SHA1;
SHA1.AddFD(fd.Fd(), fd.Size());
string local_sha1 = string(SHA1.Result());
+ if(Debug)
+ std::clog << "QueueNextDiff: "
+ << FinalFile << " (" << local_sha1 << ")"<<std::endl;
// remove all patches until the next matching patch is found
// this requires the Index file to be ordered
#define BUF_SIZE (1024)
-// XX use enums
+// XXX use enums
#define MODE_CHANGED 0
#define MODE_DELETED 1
#define MODE_ADDED 2
+#define ED_OK 0
#define ED_ORDERING 1
#define ED_PARSER 2
#define ED_FAILURE 3
+// XXX someone better go out and understand the error reporting/handling here...
int ed_rec(FILE *ed_cmds, FILE *in_file, FILE *out_file, int line,
char *buffer, unsigned int bufsize, Hashes *hash) {
int pos;
if (result > 0) {
while (fgets(buffer, BUF_SIZE, in_file) != NULL) {
written = fwrite(buffer, 1, strlen(buffer), out_file);
- // XXX add to hash
- // sha_process_bytes(buffer, written, &sha);
+ hash->Add((unsigned char*)buffer, written);
}
}
else {
fprintf(stderr, "Error: %i\n", result);
return ED_FAILURE;
}
- return 0;
+ return ED_OK;
}
FILE* fPatch = fdopen(Patch.Fd(), "r");
FILE* fTo = fdopen(To.Fd(), "w");
// now do the actual patching
- ed_file(fPatch, fFrom, fTo, &Hash);
-
- // XXX need to get the size
- // Res.Size = Buf.st_size;
+ if (ed_file(fPatch, fFrom, fTo, &Hash) != ED_OK) {
+ return false;
+ }
+
+ // write out the result
+ fflush(fFrom);
+ fflush(fPatch);
+ fflush(fTo);
+ From.Close();
+ Patch.Close();
+ To.Close();
+
+ // Transfer the modification times
+ struct stat Buf;
+ if (stat(Path.c_str(),&Buf) != 0)
+ return _error->Errno("stat",_("Failed to stat"));
+
+ struct utimbuf TimeBuf;
+ TimeBuf.actime = Buf.st_atime;
+ TimeBuf.modtime = Buf.st_mtime;
+ if (utime(Itm->DestFile.c_str(),&TimeBuf) != 0)
+ return _error->Errno("utime",_("Failed to set modification time"));
+
+ if (stat(Itm->DestFile.c_str(),&Buf) != 0)
+ return _error->Errno("stat",_("Failed to stat"));
+
+ // return done
+ Res.LastModified = Buf.st_mtime;
+ Res.Size = Buf.st_size;
Res.TakeHashes(Hash);
URIDone(Res);
-
+
return true;
}
/*}}}*/