[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

rsync support for apt



Hi,

since I'm doing a lot of rsync work lately I thought about writeing
some support for apt for rsync.

I used the copy method as template (probably should have used http
instead, I know, but copy looked so simple). The support works, but is
far from optimal. Its more like a proof of concept.

I know have several problems:
- DestFile is Packages and not Packages.gz with SourceFile Packages.gz
- DestFile is in partial, so I miss the old version of the file to
  rsync against.
- Packages.gz is requested and not Packages

So some general changes are needed or some crude hacks.
I think it might be a good idea to specify for each protocol what
extension to use for the Packages files and wether an old version
should be copied as template before requesting a fetch.

Currently rsync is the only protocol that needs this, but I hate to
hardcode that somewhere in apts source just for rsync.

Alternatively the FetchItem could contain a path and filename to an
older version of the file to fetch and rsync has to copy that itself.
Also each method itself could tell apt weather the downloaded file
needs decompression simply by the extension used in the
FetchResult->Filename. If the file ends in .gz, uncompress it.

So which method should I pursue?

MfG
        Goswin

----------------------] methods/rsync.cc [-------------------------------

// -*- mode: cpp; mode: fold -*-
// Description                                                          /*{{{*/
// $Id: rsync.cc,v 1.6 1999/01/20 04:36:43 jgg Exp $
/* ######################################################################

   Rsync URI - This method takes a uri like a file: uri and copies it
   to the destination file.
   
   ##################################################################### */
                                                                        /*}}}*/
// Include Files                                                        /*{{{*/
#include <apt-pkg/fileutl.h>
#include <apt-pkg/acquire-method.h>
#include <apt-pkg/error.h>

#include <sys/stat.h>
#include <utime.h>
#include <unistd.h>
#include <stdlib.h>
                                                                        /*}}}*/

class RsyncMethod : public pkgAcqMethod
{
   virtual bool Fetch(FetchItem *Itm);
   
   public:
   
   RsyncMethod() : pkgAcqMethod("1.0",SingleInstance) {};
};

// RsyncMethod::Fetch - Fetch a file                                    /*{{{*/
// ---------------------------------------------------------------------
/* */
bool RsyncMethod::Fetch(FetchItem *Itm)
{
  string File = Itm->Uri.substr(6);

  FetchResult Res;
  Res.Size = 1;
  Res.Filename = Itm->DestFile;
  Res.LastModified = 0;
  Res.IMSHit = false;      
  URIStart(Res);
  if (system(("rsync --partial" + File + " " + Itm->DestFile).c_str()) == 0) {
    URIDone(Res);
    return true;
  } else {
    return false;
  }
}
                                                                        /*}}}*/

int main()
{
   RsyncMethod Mth;
   return Mth.Run();
}



Reply to: