Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cSyncDir.h
Go to the documentation of this file.
1 //
4 //
5 #ifndef _INC_cSyncDir_H
6 #define _INC_cSyncDir_H
7 #ifndef NO_PRAGMA_ONCE
8 #pragma once
9 #endif
10 
11 #include "../FileSys/cManifestDir.h"
13 
14 namespace GrayLib
15 {
17  {
21  CSYNC_None = 0,
26  };
27 
29  {
31 #define cSyncDirOpDef(a,b) CSYNCOP_##a,
32 #include "cSyncDirOps.tbl"
33 #undef cSyncDirOpDef
35  };
36 
37  class GRAYLIB_LINK cSyncOp : public cRefBase
38  {
42 
43  public:
44  cSyncOp* const m_pParent;
47 
51 
52  public:
53  cSyncOp(cSyncOp* pParent, CSYNCOP_TYPE eOp, cManifestElem* pElem)
54  : m_pParent(pParent)
55  , m_eOp(eOp)
56  , m_pElem(pElem)
57  , m_eChildOpTypes(CSYNC_None)
58  {
59  ASSERT(eOp >= CSYNCOP_Null && eOp < CSYNCOP_QTY);
60  ASSERT(pElem != nullptr);
61  }
63  {
64  }
65 
66 #ifdef _DEBUG
67  static const char* GRAYCALL GetOpStr(CSYNCOP_TYPE eOp);
68 #endif
69 
71  {
72  return m_pElem->get_Name();
73  }
74  bool isAttrDir() const
75  {
76  return m_pElem->m_ElemData.isAttrDir();
77  }
78 
80  {
81  if (m_pParent != nullptr)
82  {
83  // recurse up my parent tree.
84  return cFilePath::CombineFilePathX(m_pParent->get_RelativePath(), get_Name());
85  }
86  return get_Name();
87  }
88 
89  static inline bool IsOpPull(CSYNCOP_TYPE eOp)
90  {
91  return(eOp < CSYNCOP_RemoteStub);
92  }
93  bool IsOpPull() const
94  {
95  return IsOpPull(m_eOp);
96  }
97 
99  {
100  if (eOp == CSYNCOP_Null) // nothing.
101  return;
102  if (IsOpPull(eOp))
103  {
104  m_eChildOpTypes = (CSYNC_TYPE)(m_eChildOpTypes | CSYNC_Pull);
105  }
106  else
107  {
108  m_eChildOpTypes = (CSYNC_TYPE)(m_eChildOpTypes | CSYNC_Push);
109  }
110  }
111 
112  void AddChildOp(cSyncOp* pOp)
113  {
114  ASSERT(pOp != nullptr);
115  ASSERT(pOp->m_pParent == this);
116  AddChildOpType(pOp->m_eOp);
117  m_aChildElems.Add(pOp);
118  }
119  };
121 
123  {
127 
128  public:
129  static const FILECHAR_t sm_szLimboDir[];
130 
133 
136 
139 
140  public:
141  cSyncContext(cStringF sDirRoot, const FILECHAR_t* pszManifestFileName = nullptr, cLogProcessor* pLog = nullptr, IStreamProgressCallback* pProgress = nullptr);
142  cSyncContext(const cManifestContext& context);
143  ~cSyncContext();
144 
145  HRESULT _cdecl LogFileOpf(LOG_ATTR_MASK_t uAttrMask, LOGLEV_TYPE eLogLevel, const FILECHAR_t* pszFile, const LOGCHAR_t* pszFormat, ...);
146 
147  HRESULT SendFile(cStringF sFilePathSrc, cStringF sRelPathDest, IStreamProgressCallback* pProgress1 = nullptr, FILE_SIZE_t nOffset = 0, FILE_SIZE_t nSize = (FILE_SIZE_t)-1);
148  HRESULT RequestFile(cStringF sRelPathSrc, cStringF sFilePathDest, IStreamProgressCallback* pProgress1 = nullptr, FILE_SIZE_t nOffset = 0, FILE_SIZE_t* pnSizeEst = nullptr);
149 
150  cStringF GetManifestCacheName(cStringF sManRemoteDir) const;
151  HRESULT FlushManifestCache(cStringF sManRemoteDir = "");
152  HRESULT SyncManifestFromCache(cManifestDir& manRemote, cStringF sManRemoteDest);
153  HRESULT SyncManifestFromRemote2(cManifestDir& manRemote, cStringF sManRemoteDir, cStringF sManifestCacheName);
154  HRESULT SyncManifestFromRemote(cManifestDir& manRemote, cStringF sManRemoteDir);
155 
156  HRESULT SyncIfChanged(cManifestDir& manRemote, const FILECHAR_t* pszSrcName, const FILECHAR_t* pszLocalName = nullptr);
157  HRESULT SyncDirPackage(cStringF sPathLocalDir);
158 
159  HRESULT SetLocalAttr(const FILECHAR_t* pszLocalPath, const cManifestElem* pFileDst, bool bSetName);
160  HRESULT SetLocalAttrAndCRC(const FILECHAR_t* pszLocalPath, const cManifestElem* pFileDst, bool bSetName);
161  HRESULT SetLocalAttr2(const FILECHAR_t* pszLocalPath, const cManifestElem* pFileDst, bool bSetName);
162 
163  static HRESULT GRAYCALL DoMoveLimboFiles(const FILECHAR_t* pszRootDir, cLogProcessor* pLog, IStreamProgressCallback* pProgress);
164  };
165 
167  {
172 
173  typedef cManifestBuilder SUPER_t;
174 
175  public:
177 
178  // control params
179  bool m_bRootOnly;
182 
183  // How many bytes to check? Total bytes in manifests.
187 
188  protected:
189  HRESULT UpdateProgress();
190 
191  void BuildOpAdd(cSyncOp* pOp);
192  HRESULT BuildOpDir2(cSyncOp* pOpDir, COMPARE_t iComp, cManifestElem* pFileElem);
193  HRESULT BuildOpElem(cSyncOp* pOpDir, const cManifestDir& manLocal, cManifestElem* pFileRemote, cManifestElem* pFileLocal);
194  HRESULT BuildOpDir(cSyncOp* pOpDir);
195 
196  public:
197  cSyncBuilder(cSyncContext& context);
198  virtual ~cSyncBuilder();
199 
200  bool isEstimateComplete() const
201  {
204  return m_bEstimateComplete;
205  }
206 
207  HRESULT BuildOpList(const FILECHAR_t* pszRelativePath = nullptr, CSYNC_TYPE eSyncType = CSYNC_Pull); // First pass. estimate.
208  };
209 
211  {
219 
220  public:
221  static const LOGCHAR_t sm_szFileInLimbo[];
222 
224 
226 
230 
231  protected:
232  // list of operations to perform.
234 
235  protected:
236  virtual HRESULT _stdcall onProgressCallback(const cStreamProgress& progress) override;
237 
238  HRESULT DoOp_LocalAttr(cManifestDir* pManLocal);
239  HRESULT DoOp_PullFromRemote(cManifestDir* pManLocal);
240  HRESULT DoOp_LocalDelete(cManifestDir* pManLocal);
241 
242  HRESULT DoOp_RemoteAttr();
243  HRESULT DoOp_PushToRemote();
244  HRESULT DoOp_RemoteDelete();
245 
246  HRESULT DoOp_Dir();
247  HRESULT ExecSyncOp(cManifestDir* pManLocal, cSyncOp* pOp);
248 
249  public:
250  cSyncDir(cSyncContext& context);
251  virtual ~cSyncDir();
252 
253  HRESULT ExecSyncOps(); // Second pass. start moving the files.
254  };
255 }
256 
257 #endif
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define ASSERT(exp)
Definition: cDebugAssert.h:87
Definition: cManifestDir.h:238
Definition: cManifestDir.h:215
Definition: cManifestDir.h:97
Definition: cManifestDir.h:72
Definition: cSyncDir.h:167
CSYNC_TYPE m_eSyncType
What type of sync do i want to perform.
Definition: cSyncDir.h:180
bool isEstimateComplete() const
Definition: cSyncDir.h:200
cSyncContext & m_Context
Definition: cSyncDir.h:176
bool m_bRootOnly
just sync the root only. don't descend child dirs.
Definition: cSyncDir.h:179
cArraySortString< FILECHAR_t > m_aLockedFiles
Files/Directories to be ignored. (NOT synced even tho the manifest says they should be)
Definition: cSyncDir.h:181
bool m_bEstimateComplete
the estimation pass is complete. m_Context.m_Rx and m_Context.m_Tx are set.
Definition: cSyncDir.h:186
cStreamProgress m_Local
Total bytes declared in the top level local/client manifest. >= m_Context.m_Tx.
Definition: cSyncDir.h:185
cStreamProgress m_Remote
Total bytes declared in the top level server/remote manifest. >= m_Context.m_Rx.
Definition: cSyncDir.h:184
Definition: cSyncDir.h:123
IFileCopier * m_pRemoteConnect
transfer remote files via this connection to a remote file system. If we are CSYNC_Push then it must ...
Definition: cSyncDir.h:131
TIMESECD_t m_nManifestCacheAge
allow remote/server Manifest cache to be this old. (seconds), 0=no cache.
Definition: cSyncDir.h:134
cStreamProgress m_Tx
total file data to push.
Definition: cSyncDir.h:138
cSyncOpPtr m_pOpRoot
full list/tree of operations to be performed on all dirs
Definition: cSyncDir.h:132
cStringF m_sManCachePrefix
file path prefix (Destination directory) for caching manifests.
Definition: cSyncDir.h:135
cStreamProgress m_Rx
total file data to pull.
Definition: cSyncDir.h:137
Definition: cSyncDir.h:211
bool m_bRecycleDeletes
send deletes to the recycle bin.
Definition: cSyncDir.h:225
FILE_SIZE_t m_TxPrev
previous to the IStreamProgressCallback callback.
Definition: cSyncDir.h:229
cSyncOpPtr m_pOpCur
the current operation/action for ExecSyncOp.
Definition: cSyncDir.h:233
cSyncContext & m_Context
Definition: cSyncDir.h:223
FILE_SIZE_t m_RxPrev
How many bytes to move? (on ExecSyncOps)
Definition: cSyncDir.h:228
Definition: cSyncDir.h:38
cSyncOp(cSyncOp *pParent, CSYNCOP_TYPE eOp, cManifestElem *pElem)
Definition: cSyncDir.h:53
bool IsOpPull() const
Definition: cSyncDir.h:93
CSYNCOP_TYPE m_eOp
What operation to perform on m_pElem?
Definition: cSyncDir.h:45
CSYNC_TYPE m_eChildOpTypes
If this is a directory.
Definition: cSyncDir.h:49
cSyncOp *const m_pParent
May parent directory operation.
Definition: cSyncDir.h:44
cManifestElemPtr const m_pElem
the file that will result from this operation. (local manifest)
Definition: cSyncDir.h:46
~cSyncOp()
Definition: cSyncDir.h:62
cArraySortName< cSyncOp > m_aChildElems
the list of file operations to perform in this directory.
Definition: cSyncDir.h:50
cStringF get_Name() const
Definition: cSyncDir.h:70
static bool IsOpPull(CSYNCOP_TYPE eOp)
Definition: cSyncDir.h:89
void AddChildOp(cSyncOp *pOp)
Definition: cSyncDir.h:112
cStringF get_RelativePath() const
Definition: cSyncDir.h:79
bool isAttrDir() const
Definition: cSyncDir.h:74
void AddChildOpType(CSYNCOP_TYPE eOp)
Definition: cSyncDir.h:98
Definition: cArraySortRef.h:199
ITERATE_t Add(TYPE_ARG pNew)
Definition: cArraySort.h:186
static cStringF __stdcall CombineFilePathX(const FILECHAR_t *pszBase, const FILECHAR_t *pszName, FILECHAR_t chSep=k_DirSep)
Definition: cFilePath.cpp:596
Definition: cLogAppender.h:168
Definition: cRefPtr.h:22
Definition: cRefPtr.h:225
Definition: cMesh.h:22
CSYNC_TYPE
Definition: cSyncDir.h:17
@ CSYNC_Push
Push local to remote/server. local is master copy.
Definition: cSyncDir.h:23
@ CSYNC_Newer
Push or pull if the file is newer than the other side. AKA Sync. neither side is master copy.
Definition: cSyncDir.h:24
@ CSYNC_Pull
Pull remote/server side file to local. server is master copy. (normal case)
Definition: cSyncDir.h:22
@ CSYNC_None
Don't do any sync on this directory. local manifest build only.
Definition: cSyncDir.h:21
@ CSYNC_QTY
Unknown/default sync.
Definition: cSyncDir.h:25
CSYNCOP_TYPE
Definition: cSyncDir.h:29
@ CSYNCOP_QTY
Definition: cSyncDir.h:34
cRefPtr< cSyncOp > cSyncOpPtr
Definition: cSyncDir.h:120
int COMPARE_t
result of compare. 0=same, 1=a>b, -1=a<b
Definition: cValT.h:17
LOGLEV_TYPE
Definition: cLogLevel.h:22
UINT32 LOG_ATTR_MASK_t
Definition: cLogAppender.h:56
int TIMESECD_t
signed delta seconds. like TIMESEC_t. redefined in TimeUnits.h.
Definition: cTimeSys.h:19
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
char LOGCHAR_t
always just use UTF8 for logs, don't bother with UNICODE.
Definition: cLogLevel.h:17
UINT64 FILE_SIZE_t
similar to STREAM_POS_t size_t
Definition: cFileStatus.h:31
Definition: cFileCopier.h:17
Definition: cStreamProgress.h:168