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