compare.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: compare.h,v 1.3 1999/01/17 22:00:51 jgg Exp $
  4. /* ######################################################################
  5. Compare a file list with a local directory
  6. The Compare class looks at the file list and then generates events
  7. to cause the local directory tree to become syncronized with the
  8. remote tree.
  9. The Correct class takes the events and applies them to the local tree.
  10. It only applies information that is stored in the file list, another
  11. class will have to hook the events to actually fetch files for download.
  12. ##################################################################### */
  13. /*}}}*/
  14. #ifndef DSYNC_COMPARE
  15. #define DSYNC_COMPARE
  16. #ifdef __GNUG__
  17. #pragma interface "dsync/compare.h"
  18. #endif
  19. #include <dsync/filelist.h>
  20. class dsDirCompare
  21. {
  22. unsigned int IndexSize;
  23. unsigned int IndexAlloc;
  24. unsigned int *Indexes;
  25. unsigned int NameAlloc;
  26. char *Names;
  27. protected:
  28. // Location of the tree
  29. string Base;
  30. // Scan helpers
  31. bool LoadDir();
  32. bool DoDelete(string Dir);
  33. bool Fetch(dsFList &List,string Dir,struct stat *St);
  34. bool DirExists(string Name);
  35. virtual bool CheckHash(dsFList &List,string Dir,unsigned char MD5[16]);
  36. virtual bool FixMeta(dsFList &List,string Dir,struct stat &St);
  37. virtual bool Visit(dsFList &List,string Dir) {return true;};
  38. // Derived classes can hook these to actuall make them do something
  39. virtual bool GetNew(dsFList &List,string Dir) {return true;};
  40. virtual bool Delete(string Dir,const char *Name,bool Now = false) {return true;};
  41. virtual bool GetChanged(dsFList &List,string Dir) {return true;};
  42. virtual bool SetTime(dsFList &List,string Dir) {return true;};
  43. virtual bool SetPerm(dsFList &List,string Dir) {return true;};
  44. virtual bool SetOwners(dsFList &List,string Dir) {return true;};
  45. public:
  46. bool Verify;
  47. enum {Md5Never, Md5Date, Md5Always} HashLevel;
  48. bool Process(string Base,dsFList::IO &IO);
  49. dsDirCompare();
  50. virtual ~dsDirCompare();
  51. };
  52. class dsDirCorrect : public dsDirCompare
  53. {
  54. bool DirUnlink(const char *Path);
  55. protected:
  56. // Derived classes can hook these to actuall make them do something
  57. virtual bool GetNew(dsFList &List,string Dir);
  58. virtual bool Delete(string Dir,const char *Name,bool Now = false);
  59. virtual bool GetChanged(dsFList &List,string Dir);
  60. virtual bool SetTime(dsFList &List,string Dir);
  61. virtual bool SetPerm(dsFList &List,string Dir);
  62. virtual bool SetOwners(dsFList &List,string Dir);
  63. public:
  64. };
  65. #endif