dsync-flist.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: dsync-flist.h,v 1.5 1999/12/26 06:59:00 jgg Exp $
  4. /* ######################################################################
  5. Some header declarations..
  6. ##################################################################### */
  7. /*}}}*/
  8. #ifndef DSYNC_FLIST_H
  9. #define DSYNC_FLIST_H
  10. #ifdef __GNUG__
  11. #pragma interface "dsync-flist.h"
  12. #endif
  13. #include <dsync/genfilelist.h>
  14. #include <dsync/fileutl.h>
  15. #include <dsync/filelistdb.h>
  16. #include <dsync/compare.h>
  17. #include <sys/time.h>
  18. #include <iostream>
  19. #include <fstream>
  20. using namespace std;
  21. extern ostream c0out;
  22. extern ostream c1out;
  23. extern ostream c2out;
  24. extern ofstream devnull;
  25. extern unsigned int ScreenWidth;
  26. class FdIO : public dsFList::IO
  27. {
  28. FileFd Fd;
  29. public:
  30. virtual bool Read(void *Buf,unsigned long Len) {return Fd.Read(Buf,Len);};
  31. virtual bool Write(const void *Buf,unsigned long Len) {return Fd.Write(Buf,Len);};
  32. virtual bool Seek(unsigned long Bytes) {return Fd.Seek(Bytes);};
  33. virtual unsigned long Tell() {return Fd.Tell();};
  34. FdIO(string File,FileFd::OpenMode Mode) : Fd(File,Mode) {};
  35. };
  36. class Progress
  37. {
  38. bool Quiet;
  39. char LastLine[300];
  40. char BlankLine[300];
  41. public:
  42. // Counters
  43. unsigned long DirCount;
  44. unsigned long FileCount;
  45. unsigned long LinkCount;
  46. unsigned long LastCount;
  47. double Bytes;
  48. double CkSumBytes;
  49. struct timeval StartTime;
  50. double ElapsedTime();
  51. void Done();
  52. void Update(const char *Dir);
  53. void Stats(bool Md5);
  54. inline void Hide()
  55. {
  56. if (Quiet == false)
  57. c0out << '\r' << BlankLine << '\r';
  58. };
  59. inline void Show()
  60. {
  61. if (Quiet == false)
  62. c0out << LastLine << '\r' << flush;
  63. };
  64. Progress();
  65. ~Progress() {Done();};
  66. };
  67. class ListGenerator : public dsGenFileList
  68. {
  69. protected:
  70. bool Act;
  71. bool Verbose;
  72. unsigned long MinRSyncSize;
  73. unsigned int StripDepth;
  74. virtual int Visit(const char *Directory,const char *File,
  75. struct stat const &Stat);
  76. virtual bool EmitMD5(const char *Dir,const char *File,
  77. struct stat const &St,unsigned char MD5[16],
  78. unsigned int Tag,unsigned int Flag);
  79. virtual bool NeedsRSync(const char *Dir,const char *File,
  80. dsFList::NormalFile &F);
  81. public:
  82. // Md5 Cache
  83. dsFileListDB *DB;
  84. dsMMapIO *DBIO;
  85. Progress Prog;
  86. dsFileFilter RemoveFilter;
  87. dsFileFilter RSyncFilter;
  88. ListGenerator();
  89. ~ListGenerator();
  90. };
  91. class Compare : public dsDirCorrect
  92. {
  93. protected:
  94. bool Verbose;
  95. bool Act;
  96. bool DoDelete;
  97. virtual bool Visit(dsFList &List,string Dir);
  98. void PrintPath(ostream &out,string Dir,string Name);
  99. // Display status information
  100. virtual bool GetNew(dsFList &List,string Dir)
  101. {
  102. Prog.Hide();
  103. c1out << "N ";
  104. PrintPath(c1out,Dir,List.Entity->Name);
  105. Prog.Show();
  106. return !Act || dsDirCorrect::GetNew(List,Dir);
  107. };
  108. virtual bool Delete(string Dir,const char *Name,bool Now = false)
  109. {
  110. Prog.Hide();
  111. c1out << "D ";
  112. PrintPath(c1out,Dir,Name);
  113. Prog.Show();
  114. return !Act || !DoDelete || dsDirCorrect::Delete(Dir,Name);
  115. };
  116. virtual bool GetChanged(dsFList &List,string Dir)
  117. {
  118. Prog.Hide();
  119. c1out << "C ";
  120. PrintPath(c1out,Dir,List.Entity->Name);
  121. Prog.Show();
  122. return !Act || dsDirCorrect::GetChanged(List,Dir);
  123. };
  124. virtual bool SetTime(dsFList &List,string Dir)
  125. {
  126. if (Verbose == false)
  127. return !Act || dsDirCorrect::SetTime(List,Dir);
  128. Prog.Hide();
  129. c1out << "T ";
  130. PrintPath(c1out,Dir,List.Entity->Name);
  131. Prog.Show();
  132. return !Act || dsDirCorrect::SetTime(List,Dir);
  133. };
  134. virtual bool SetPerm(dsFList &List,string Dir)
  135. {
  136. if (Verbose == false)
  137. return !Act || dsDirCorrect::SetPerm(List,Dir);
  138. Prog.Hide();
  139. c1out << "P ";
  140. PrintPath(c1out,Dir,List.Entity->Name);
  141. Prog.Show();
  142. return !Act || dsDirCorrect::SetPerm(List,Dir);
  143. };
  144. virtual bool SetOwners(dsFList &List,string Dir)
  145. {
  146. if (Verbose == false)
  147. return !Act || dsDirCorrect::SetOwners(List,Dir);
  148. Prog.Hide();
  149. c1out << "O ";
  150. PrintPath(c1out,Dir,List.Entity->Name);
  151. Prog.Show();
  152. return !Act || dsDirCorrect::SetOwners(List,Dir);
  153. };
  154. virtual bool CheckHash(dsFList &List,string Dir,unsigned char MD5[16])
  155. {
  156. Prog.CkSumBytes += List.File->Size;
  157. if (Verbose == true)
  158. {
  159. Prog.Hide();
  160. c1out << "H ";
  161. PrintPath(c1out,Dir,List.Entity->Name);
  162. Prog.Show();
  163. }
  164. return dsDirCompare::CheckHash(List,Dir,MD5);
  165. }
  166. public:
  167. Progress Prog;
  168. Compare();
  169. };
  170. // Path utilities
  171. bool SimplifyPath(char *Buffer);
  172. bool ResolveLink(char *Buffer,unsigned long Max);
  173. #endif