Split filenodecmp in actionfilenode*
This commit is contained in:
17
Makefile
17
Makefile
@@ -17,14 +17,19 @@ HEADS = \
|
|||||||
src/util.h \
|
src/util.h \
|
||||||
src/crc.h \
|
src/crc.h \
|
||||||
src/fileutil.h \
|
src/fileutil.h \
|
||||||
src/filenode.h
|
src/filenode.h \
|
||||||
|
src/actionfilenode.h \
|
||||||
|
src/actionfilenodesync.h \
|
||||||
|
src/actionfilenodecopy.h
|
||||||
|
|
||||||
OBJS_BASE = \
|
OBJS_BASE = \
|
||||||
$(BUILDDIR)/util.o \
|
$(BUILDDIR)/util.o \
|
||||||
$(BUILDDIR)/crc.o \
|
$(BUILDDIR)/crc.o \
|
||||||
$(BUILDDIR)/fileutil.o \
|
$(BUILDDIR)/fileutil.o \
|
||||||
$(BUILDDIR)/filenode.o \
|
$(BUILDDIR)/filenode.o \
|
||||||
$(BUILDDIR)/filenodecmp.o
|
$(BUILDDIR)/actionfilenode.o \
|
||||||
|
$(BUILDDIR)/actionfilenodesync.o \
|
||||||
|
$(BUILDDIR)/actionfilenodecopy.o
|
||||||
|
|
||||||
OBJS_APP = \
|
OBJS_APP = \
|
||||||
$(OBJS_BASE) \
|
$(OBJS_BASE) \
|
||||||
@@ -61,9 +66,14 @@ $(BUILDDIR)/fileutil.o: src/fileutil.c $(HEADS)
|
|||||||
$(BUILDDIR)/filenode.o: src/filenode.c $(HEADS)
|
$(BUILDDIR)/filenode.o: src/filenode.c $(HEADS)
|
||||||
$(DO_CC)
|
$(DO_CC)
|
||||||
|
|
||||||
$(BUILDDIR)/filenodecmp.o: src/filenodecmp.c $(HEADS)
|
$(BUILDDIR)/actionfilenode.o: src/actionfilenode.c $(HEADS)
|
||||||
$(DO_CC)
|
$(DO_CC)
|
||||||
|
|
||||||
|
$(BUILDDIR)/actionfilenodesync.o: src/actionfilenodesync.c $(HEADS)
|
||||||
|
$(DO_CC)
|
||||||
|
|
||||||
|
$(BUILDDIR)/actionfilenodecopy.o: src/actionfilenodecopy.c $(HEADS)
|
||||||
|
$(DO_CC)
|
||||||
|
|
||||||
$(BUILDDIR)/main.o: src/main.c $(HEADS)
|
$(BUILDDIR)/main.o: src/main.c $(HEADS)
|
||||||
$(DO_CC)
|
$(DO_CC)
|
||||||
@@ -74,4 +84,3 @@ $(RES_APP): $(BUILDDIR) $(OBJS_APP)
|
|||||||
@$(CC) $(OBJS_APP) \
|
@$(CC) $(OBJS_APP) \
|
||||||
-o $(RES_APP) $(LIBS)
|
-o $(RES_APP) $(LIBS)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,14 @@
|
|||||||
<Compile Include="..\..\src\filenode.c">
|
<Compile Include="..\..\src\filenode.c">
|
||||||
<Link>src\filenode.c</Link>
|
<Link>src\filenode.c</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\..\src\filenodecmp.c">
|
<Compile Include="..\..\src\actionfilenode.c">
|
||||||
<Link>src\filenodecmp.c</Link>
|
<Link>src\actionfilenode.c</Link>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="..\..\src\actionfilenodesync.c">
|
||||||
|
<Link>src\actionfilenodesync.c</Link>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="..\..\src\actionfilenodecopy.c">
|
||||||
|
<Link>src\actionfilenodecopy.c</Link>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="..\..\src\fileutil.c">
|
<Compile Include="..\..\src\fileutil.c">
|
||||||
<Link>src\fileutil.c</Link>
|
<Link>src\fileutil.c</Link>
|
||||||
@@ -56,8 +62,14 @@
|
|||||||
<None Include="..\..\src\filenode.h">
|
<None Include="..\..\src\filenode.h">
|
||||||
<Link>src\filenode.h</Link>
|
<Link>src\filenode.h</Link>
|
||||||
</None>
|
</None>
|
||||||
<None Include="..\..\src\filenodecmp.h">
|
<None Include="..\..\src\actionfilenode.h">
|
||||||
<Link>src\filenodecmp.h</Link>
|
<Link>src\actionfilenode.h</Link>
|
||||||
|
</None>
|
||||||
|
<None Include="..\..\src\actionfilenodesync.h">
|
||||||
|
<Link>src\actionfilenodesync.h</Link>
|
||||||
|
</None>
|
||||||
|
<None Include="..\..\src\actionfilenodecopy.h">
|
||||||
|
<Link>src\actionfilenodecopy.h</Link>
|
||||||
</None>
|
</None>
|
||||||
<None Include="..\..\src\fileutil.h">
|
<None Include="..\..\src\fileutil.h">
|
||||||
<Link>src\fileutil.h</Link>
|
<Link>src\fileutil.h</Link>
|
||||||
|
|||||||
@@ -121,17 +121,21 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="..\..\src\actionfilenode.c" />
|
||||||
|
<ClCompile Include="..\..\src\actionfilenodecopy.c" />
|
||||||
|
<ClCompile Include="..\..\src\actionfilenodesync.c" />
|
||||||
<ClCompile Include="..\..\src\crc.c" />
|
<ClCompile Include="..\..\src\crc.c" />
|
||||||
<ClCompile Include="..\..\src\filenode.c" />
|
<ClCompile Include="..\..\src\filenode.c" />
|
||||||
<ClCompile Include="..\..\src\filenodecmp.c" />
|
|
||||||
<ClCompile Include="..\..\src\fileutil.c" />
|
<ClCompile Include="..\..\src\fileutil.c" />
|
||||||
<ClCompile Include="..\..\src\main.c" />
|
<ClCompile Include="..\..\src\main.c" />
|
||||||
<ClCompile Include="..\..\src\util.c" />
|
<ClCompile Include="..\..\src\util.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="..\..\src\actionfilenode.h" />
|
||||||
|
<ClInclude Include="..\..\src\actionfilenodecopy.h" />
|
||||||
|
<ClInclude Include="..\..\src\actionfilenodesync.h" />
|
||||||
<ClInclude Include="..\..\src\crc.h" />
|
<ClInclude Include="..\..\src\crc.h" />
|
||||||
<ClInclude Include="..\..\src\filenode.h" />
|
<ClInclude Include="..\..\src\filenode.h" />
|
||||||
<ClInclude Include="..\..\src\filenodecmp.h" />
|
|
||||||
<ClInclude Include="..\..\src\fileutil.h" />
|
<ClInclude Include="..\..\src\fileutil.h" />
|
||||||
<ClInclude Include="..\..\src\util.h" />
|
<ClInclude Include="..\..\src\util.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -21,9 +21,6 @@
|
|||||||
<ClCompile Include="..\..\src\filenode.c">
|
<ClCompile Include="..\..\src\filenode.c">
|
||||||
<Filter>Archivos de código fuente</Filter>
|
<Filter>Archivos de código fuente</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\src\filenodecmp.c">
|
|
||||||
<Filter>Archivos de código fuente</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="..\..\src\fileutil.c">
|
<ClCompile Include="..\..\src\fileutil.c">
|
||||||
<Filter>Archivos de código fuente</Filter>
|
<Filter>Archivos de código fuente</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@@ -33,6 +30,15 @@
|
|||||||
<ClCompile Include="..\..\src\util.c">
|
<ClCompile Include="..\..\src\util.c">
|
||||||
<Filter>Archivos de código fuente</Filter>
|
<Filter>Archivos de código fuente</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\actionfilenode.c">
|
||||||
|
<Filter>Archivos de código fuente</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\actionfilenodecopy.c">
|
||||||
|
<Filter>Archivos de código fuente</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\src\actionfilenodesync.c">
|
||||||
|
<Filter>Archivos de código fuente</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\src\crc.h">
|
<ClInclude Include="..\..\src\crc.h">
|
||||||
@@ -41,15 +47,21 @@
|
|||||||
<ClInclude Include="..\..\src\filenode.h">
|
<ClInclude Include="..\..\src\filenode.h">
|
||||||
<Filter>Archivos de encabezado</Filter>
|
<Filter>Archivos de encabezado</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\filenodecmp.h">
|
|
||||||
<Filter>Archivos de encabezado</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\src\fileutil.h">
|
<ClInclude Include="..\..\src\fileutil.h">
|
||||||
<Filter>Archivos de encabezado</Filter>
|
<Filter>Archivos de encabezado</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\src\util.h">
|
<ClInclude Include="..\..\src\util.h">
|
||||||
<Filter>Archivos de encabezado</Filter>
|
<Filter>Archivos de encabezado</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\actionfilenode.h">
|
||||||
|
<Filter>Archivos de encabezado</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\actionfilenodecopy.h">
|
||||||
|
<Filter>Archivos de encabezado</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\actionfilenodesync.h">
|
||||||
|
<Filter>Archivos de encabezado</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\README.md" />
|
<None Include="..\..\README.md" />
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -6,11 +6,7 @@
|
|||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
#include "fileutil.h"
|
#include "fileutil.h"
|
||||||
#include "filenode.h"
|
#include "filenode.h"
|
||||||
#include "filenodecmp.h"
|
#include "actionfilenode.h"
|
||||||
|
|
||||||
int maxDeltaTime = 4000;
|
|
||||||
|
|
||||||
#define QueueNode(queue,node) (queue)->next = (node); (queue) = (node);
|
|
||||||
|
|
||||||
ActionFileNode _actionFileNodeFree = NULL;
|
ActionFileNode _actionFileNodeFree = NULL;
|
||||||
#define AccionFileNode_Block 1024
|
#define AccionFileNode_Block 1024
|
||||||
@@ -63,7 +59,8 @@ ActionFileNode ActionFileNode_CreateNormal(FileNode fileNodeLeft,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AccionFileNode_CompareChilds(ActionFileNode actionFileNodeRoot,
|
void AccionFileNode_CompareChilds(
|
||||||
|
ActionFileNode actionFileNodeRoot,
|
||||||
ActionFileNode *actionFileNodeQueue,
|
ActionFileNode *actionFileNodeQueue,
|
||||||
void(*CheckPair)(FileNode fileNodeLeft, FileNode fileNodeRight,
|
void(*CheckPair)(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||||
ActionFileNode *actionFileNodeQueue))
|
ActionFileNode *actionFileNodeQueue))
|
||||||
@@ -152,373 +149,8 @@ void AccionFileNode_CompareChilds(ActionFileNode actionFileNodeRoot,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccionFileNode_DeletePair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|
||||||
ActionFileNode *actionFileNodeQueue)
|
|
||||||
{
|
|
||||||
ActionFileNode actionFileNodeNew = ActionFileNode_CreateNormal(
|
|
||||||
fileNodeLeft, fileNodeRight);
|
|
||||||
|
|
||||||
if (!fileNodeLeft && !fileNodeRight) {
|
|
||||||
AccionFileNode_Destroy(actionFileNodeNew);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!fileNodeLeft && fileNodeRight) {
|
|
||||||
if (fileNodeRight->flags & FileFlag_Directory) {
|
|
||||||
// Iterate childs for deletion
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew, actionFileNodeQueue,
|
|
||||||
AccionFileNode_DeletePair);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
|
||||||
// Node delete action
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
AccionFileNode_Destroy(actionFileNodeNew);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fileNodeLeft && !fileNodeRight) {
|
|
||||||
if (fileNodeLeft->flags & FileFlag_Directory) {
|
|
||||||
// Iterate childs for deletion
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew, actionFileNodeQueue,
|
|
||||||
AccionFileNode_DeletePair);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
|
||||||
// Node delete action
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
AccionFileNode_Destroy(actionFileNodeNew);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fileNodeLeft && fileNodeRight) {
|
|
||||||
if ((fileNodeLeft->flags & FileFlag_Directory)
|
|
||||||
|| (fileNodeRight->flags & FileFlag_Directory)) {
|
|
||||||
// One is Directory
|
|
||||||
|
|
||||||
// Iterate childs for deletion
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew, actionFileNodeQueue,
|
|
||||||
AccionFileNode_DeletePair);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
|
||||||
// Left node delete action
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
actionFileNodeNew = NULL;
|
|
||||||
}
|
|
||||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
|
||||||
if (!actionFileNodeNew) {
|
|
||||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
|
||||||
fileNodeRight);
|
|
||||||
}
|
|
||||||
// Right node delete action
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
actionFileNodeNew = NULL;
|
|
||||||
}
|
|
||||||
if (actionFileNodeNew) {
|
|
||||||
AccionFileNode_Destroy(actionFileNodeNew);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void AccionFileNode_SyncPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|
||||||
ActionFileNode *actionFileNodeQueue)
|
|
||||||
{
|
|
||||||
ActionFileNode actionFileNodeNew = ActionFileNode_CreateNormal(
|
|
||||||
fileNodeLeft, fileNodeRight);
|
|
||||||
|
|
||||||
if (!fileNodeLeft && !fileNodeRight) {
|
|
||||||
AccionFileNode_Destroy(actionFileNodeNew);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!fileNodeLeft && fileNodeRight) {
|
|
||||||
if (fileNodeRight->flags & FileFlag_Directory) {
|
|
||||||
// Directory
|
|
||||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_MakeLeftDirectory;
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
|
|
||||||
// Iterate childs
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
|
||||||
actionFileNodeQueue, AccionFileNode_SyncPair);
|
|
||||||
|
|
||||||
// Creatre new action for date copy
|
|
||||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
|
||||||
fileNodeRight);
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DateRightToLeft;
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// File
|
|
||||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_RightToLeft;
|
|
||||||
}
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fileNodeLeft && !fileNodeRight) {
|
|
||||||
if (fileNodeLeft->flags & FileFlag_Directory) {
|
|
||||||
// Directory
|
|
||||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_MakeRightDirectory;
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
|
|
||||||
// Iterate childs
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
|
||||||
actionFileNodeQueue, AccionFileNode_SyncPair);
|
|
||||||
|
|
||||||
// Create new action for date copy
|
|
||||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
|
||||||
fileNodeRight);
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// File
|
|
||||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
|
||||||
}
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fileNodeLeft && fileNodeRight) {
|
|
||||||
if ((fileNodeLeft->flags & FileFlag_Directory)
|
|
||||||
&& (fileNodeRight->flags & FileFlag_Directory))
|
|
||||||
{
|
|
||||||
// Directory
|
|
||||||
|
|
||||||
// Prepare action for directory pair
|
|
||||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime)) <= maxDeltaTime) { // aprox. equal
|
|
||||||
if (fileNodeRight->status == FileStatus_Deleted
|
|
||||||
&& fileNodeLeft->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
else if (fileNodeRight->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
|
||||||
}
|
|
||||||
else if (fileNodeLeft->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DateRightToLeft;
|
|
||||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
|
||||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
|
||||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
|
||||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process child nodes
|
|
||||||
if (actionFileNodeNew->action == ActionFileCmp_DeleteRight
|
|
||||||
|| actionFileNodeNew->action == ActionFileCmp_DeleteLeft
|
|
||||||
|| (fileNodeLeft->status == FileStatus_Deleted
|
|
||||||
&& fileNodeRight->status == FileStatus_Deleted)) {
|
|
||||||
// Iterate child nodes for deletion
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
|
||||||
actionFileNodeQueue, AccionFileNode_DeletePair);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
|
||||||
actionFileNodeQueue, AccionFileNode_SyncPair);
|
|
||||||
}
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
else if ((fileNodeLeft->flags & FileFlag_Normal)
|
|
||||||
&& (fileNodeRight->flags & FileFlag_Normal))
|
|
||||||
{
|
|
||||||
// Files
|
|
||||||
|
|
||||||
// Prepare action for file pair
|
|
||||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime)) <= maxDeltaTime) { // aprox. equal
|
|
||||||
if (fileNodeRight->status == FileStatus_Deleted
|
|
||||||
&& fileNodeLeft->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
else if (fileNodeRight->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
|
||||||
}
|
|
||||||
else if (fileNodeLeft->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
|
||||||
// FIXME: Check size to determine y further checks are necessary
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_RightToLeft;
|
|
||||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
|
||||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
|
||||||
// FIXME: Check size to determine y further checks are necessary
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
|
||||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
|
||||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// FIXME: !!!!!
|
|
||||||
// Directory vs File
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ActionFileNode ActionFileNode_BuildSync(FileNode izquierda, FileNode derecha) {
|
|
||||||
ActionFileNode actionFileNodeRoot = ActionFileNode_CreateNormal(izquierda,
|
|
||||||
derecha);
|
|
||||||
ActionFileNode actionFileNodeQueue = actionFileNodeRoot;
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
|
||||||
AccionFileNode_SyncPair);
|
|
||||||
return actionFileNodeRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AccionFileNode_Copy(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|
||||||
ActionFileNode *actionFileNodeQueue)
|
|
||||||
{
|
|
||||||
ActionFileNode actionFileNodeNew = ActionFileNode_CreateNormal(
|
|
||||||
fileNodeLeft, fileNodeRight);
|
|
||||||
|
|
||||||
if (!fileNodeLeft && !fileNodeRight) {
|
|
||||||
AccionFileNode_Destroy(actionFileNodeNew);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!fileNodeLeft && fileNodeRight) {
|
|
||||||
if (fileNodeRight->flags & FileFlag_Directory) {
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew, actionFileNodeQueue,
|
|
||||||
AccionFileNode_DeletePair);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
if (fileNodeLeft && !fileNodeRight) {
|
|
||||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
|
||||||
if (fileNodeLeft->flags & FileFlag_Directory) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_MakeRightDirectory;
|
|
||||||
(*actionFileNodeQueue)->next = actionFileNodeNew;
|
|
||||||
(*actionFileNodeQueue) = actionFileNodeNew;
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
|
||||||
actionFileNodeQueue, AccionFileNode_Copy);
|
|
||||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
|
||||||
fileNodeRight);
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
if (fileNodeLeft && fileNodeRight) {
|
|
||||||
if ((fileNodeLeft->flags & FileFlag_Directory)
|
|
||||||
|| (fileNodeRight->flags & FileFlag_Directory))
|
|
||||||
{
|
|
||||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
|
||||||
actionFileNodeQueue, AccionFileNode_Copy);
|
|
||||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime))
|
|
||||||
<= maxDeltaTime) { // appox. equal
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
|
||||||
actionFileNodeQueue, AccionFileNode_DeletePair);
|
|
||||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
|
||||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime))
|
|
||||||
<= maxDeltaTime)
|
|
||||||
{
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ActionFileNode ActionFileNode_BuildCopy(FileNode fileNodeLeft,
|
|
||||||
FileNode fileNodeRight) {
|
|
||||||
ActionFileNode actionFileNodeRoot = ActionFileNode_CreateNormal(
|
|
||||||
fileNodeLeft, fileNodeRight);
|
|
||||||
ActionFileNode actionFileNodeQueue = actionFileNodeRoot;
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
|
||||||
AccionFileNode_Copy);
|
|
||||||
return actionFileNodeRoot;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ActionFileNode_Statistics(ActionFileNode actionFileNode,
|
void ActionFileNode_Statistics(ActionFileNode actionFileNode,
|
||||||
ActionQueueStatistics *statistics)
|
ActionQueueStatistics *statistics)
|
||||||
{
|
{
|
||||||
statistics->readLeft = 0;
|
statistics->readLeft = 0;
|
||||||
statistics->writeLeft = 0;
|
statistics->writeLeft = 0;
|
||||||
@@ -643,7 +275,7 @@ void AccionFileNodeAux_MakeDir(char *pathOrig, char *pathDest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ActionFileNode_RunList(ActionFileNode actionFileNode, char *pathLeft,
|
void ActionFileNode_RunList(ActionFileNode actionFileNode, char *pathLeft,
|
||||||
char *pathRight)
|
char *pathRight)
|
||||||
{
|
{
|
||||||
char fullPathLeft[MaxPath], fullPathRight[MaxPath], showPath[MaxPath];
|
char fullPathLeft[MaxPath], fullPathRight[MaxPath], showPath[MaxPath];
|
||||||
while (actionFileNode != NULL) {
|
while (actionFileNode != NULL) {
|
||||||
@@ -706,3 +338,83 @@ void ActionFileNode_RunList(ActionFileNode actionFileNode, char *pathLeft,
|
|||||||
}
|
}
|
||||||
printff("End\n");
|
printff("End\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Common utilities
|
||||||
|
|
||||||
|
#define QueueNode(queue,node) (queue)->next = (node); (queue) = (node);
|
||||||
|
|
||||||
|
void AccionFileNode_DeletePair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||||
|
ActionFileNode *actionFileNodeQueue)
|
||||||
|
{
|
||||||
|
ActionFileNode actionFileNodeNew = ActionFileNode_CreateNormal(
|
||||||
|
fileNodeLeft, fileNodeRight);
|
||||||
|
|
||||||
|
if (!fileNodeLeft && !fileNodeRight) {
|
||||||
|
AccionFileNode_Destroy(actionFileNodeNew);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!fileNodeLeft && fileNodeRight) {
|
||||||
|
if (fileNodeRight->flags & FileFlag_Directory) {
|
||||||
|
// Iterate childs for deletion
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeNew, actionFileNodeQueue,
|
||||||
|
AccionFileNode_DeletePair);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||||
|
// Node delete action
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AccionFileNode_Destroy(actionFileNodeNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fileNodeLeft && !fileNodeRight) {
|
||||||
|
if (fileNodeLeft->flags & FileFlag_Directory) {
|
||||||
|
// Iterate childs for deletion
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeNew, actionFileNodeQueue,
|
||||||
|
AccionFileNode_DeletePair);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||||
|
// Node delete action
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AccionFileNode_Destroy(actionFileNodeNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fileNodeLeft && fileNodeRight) {
|
||||||
|
if ((fileNodeLeft->flags & FileFlag_Directory)
|
||||||
|
|| (fileNodeRight->flags & FileFlag_Directory)) {
|
||||||
|
// One is Directory
|
||||||
|
|
||||||
|
// Iterate childs for deletion
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeNew, actionFileNodeQueue,
|
||||||
|
AccionFileNode_DeletePair);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||||
|
// Left node delete action
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
actionFileNodeNew = NULL;
|
||||||
|
}
|
||||||
|
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||||
|
if (!actionFileNodeNew) {
|
||||||
|
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
||||||
|
fileNodeRight);
|
||||||
|
}
|
||||||
|
// Right node delete action
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
actionFileNodeNew = NULL;
|
||||||
|
}
|
||||||
|
if (actionFileNodeNew) {
|
||||||
|
AccionFileNode_Destroy(actionFileNodeNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef _FILENODECMP_H_
|
#ifndef _ACTIONFILENODE_H_
|
||||||
#define _FILENODECMP_H_
|
#define _ACTIONFILENODE_H_
|
||||||
|
|
||||||
#include "filenode.h"
|
#include "filenode.h"
|
||||||
|
|
||||||
@@ -28,10 +28,11 @@ void AccionFileNode_Destroy(ActionFileNode actionFileNode);
|
|||||||
ActionFileNode ActionFileNode_CreateNormal(FileNode fileNodeLeft,
|
ActionFileNode ActionFileNode_CreateNormal(FileNode fileNodeLeft,
|
||||||
FileNode fileNodeRight);
|
FileNode fileNodeRight);
|
||||||
|
|
||||||
ActionFileNode ActionFileNode_BuildSync(FileNode fileNodeLeft,
|
void AccionFileNode_CompareChilds(
|
||||||
FileNode fileNodeRight);
|
ActionFileNode actionFileNodeRoot,
|
||||||
ActionFileNode ActionFileNode_BuildCopy(FileNode fileNodeLeft,
|
ActionFileNode *actionFileNodeQueue,
|
||||||
FileNode fileNodeRight);
|
void(*CheckPair)(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||||
|
ActionFileNode *actionFileNodeQueue));
|
||||||
|
|
||||||
typedef struct SActionQueueStatistics {
|
typedef struct SActionQueueStatistics {
|
||||||
long long readLeft;
|
long long readLeft;
|
||||||
@@ -54,4 +55,10 @@ void ActionFileNode_Print(ActionFileNode actionFileNode);
|
|||||||
void ActionFileNode_RunList(ActionFileNode actionFileNode, char *pathLeft,
|
void ActionFileNode_RunList(ActionFileNode actionFileNode, char *pathLeft,
|
||||||
char *pathRight);
|
char *pathRight);
|
||||||
|
|
||||||
|
|
||||||
|
// Common utilities
|
||||||
|
|
||||||
|
void AccionFileNode_DeletePair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||||
|
ActionFileNode *actionFileNodeQueue);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
115
src/actionfilenodecopy.c
Normal file
115
src/actionfilenodecopy.c
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
#include "crc.h"
|
||||||
|
#include "fileutil.h"
|
||||||
|
#include "filenode.h"
|
||||||
|
#include "actionfilenode.h"
|
||||||
|
#include "actionfilenodesync.h"
|
||||||
|
|
||||||
|
#define maxDeltaTime 4000
|
||||||
|
|
||||||
|
#define QueueNode(queue,node) (queue)->next = (node); (queue) = (node);
|
||||||
|
|
||||||
|
|
||||||
|
void AccionFileNode_CopyPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||||
|
ActionFileNode *actionFileNodeQueue)
|
||||||
|
{
|
||||||
|
ActionFileNode actionFileNodeNew = ActionFileNode_CreateNormal(
|
||||||
|
fileNodeLeft, fileNodeRight);
|
||||||
|
|
||||||
|
if (!fileNodeLeft && !fileNodeRight) {
|
||||||
|
AccionFileNode_Destroy(actionFileNodeNew);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!fileNodeLeft && fileNodeRight) {
|
||||||
|
if (fileNodeRight->flags & FileFlag_Directory) {
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeNew, actionFileNodeQueue,
|
||||||
|
AccionFileNode_DeletePair);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
if (fileNodeLeft && !fileNodeRight) {
|
||||||
|
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||||
|
if (fileNodeLeft->flags & FileFlag_Directory) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_MakeRightDirectory;
|
||||||
|
(*actionFileNodeQueue)->next = actionFileNodeNew;
|
||||||
|
(*actionFileNodeQueue) = actionFileNodeNew;
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
|
actionFileNodeQueue, AccionFileNode_CopyPair);
|
||||||
|
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
||||||
|
fileNodeRight);
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
if (fileNodeLeft && fileNodeRight) {
|
||||||
|
if ((fileNodeLeft->flags & FileFlag_Directory)
|
||||||
|
|| (fileNodeRight->flags & FileFlag_Directory))
|
||||||
|
{
|
||||||
|
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
|
actionFileNodeQueue, AccionFileNode_CopyPair);
|
||||||
|
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime))
|
||||||
|
<= maxDeltaTime) { // appox. equal
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
|
actionFileNodeQueue, AccionFileNode_DeletePair);
|
||||||
|
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||||
|
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime))
|
||||||
|
<= maxDeltaTime)
|
||||||
|
{
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionFileNode ActionFileNode_BuildCopy(FileNode fileNodeLeft,
|
||||||
|
FileNode fileNodeRight) {
|
||||||
|
ActionFileNode actionFileNodeRoot = ActionFileNode_CreateNormal(
|
||||||
|
fileNodeLeft, fileNodeRight);
|
||||||
|
ActionFileNode actionFileNodeQueue = actionFileNodeRoot;
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
||||||
|
AccionFileNode_CopyPair);
|
||||||
|
return actionFileNodeRoot;
|
||||||
|
}
|
||||||
|
|
||||||
10
src/actionfilenodecopy.h
Normal file
10
src/actionfilenodecopy.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef _ACTIONFILENODECOPY_H_
|
||||||
|
#define _ACTIONFILENODECOPY_H_
|
||||||
|
|
||||||
|
#include "filenode.h"
|
||||||
|
#include "actionfilenode.h"
|
||||||
|
|
||||||
|
ActionFileNode ActionFileNode_BuildCopy(FileNode fileNodeLeft,
|
||||||
|
FileNode fileNodeRight);
|
||||||
|
|
||||||
|
#endif
|
||||||
206
src/actionfilenodesync.c
Normal file
206
src/actionfilenodesync.c
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
#include "crc.h"
|
||||||
|
#include "fileutil.h"
|
||||||
|
#include "filenode.h"
|
||||||
|
#include "actionfilenode.h"
|
||||||
|
#include "actionfilenodesync.h"
|
||||||
|
|
||||||
|
#define maxDeltaTime 4000
|
||||||
|
|
||||||
|
#define QueueNode(queue,node) (queue)->next = (node); (queue) = (node);
|
||||||
|
|
||||||
|
void AccionFileNode_SyncPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||||
|
ActionFileNode *actionFileNodeQueue)
|
||||||
|
{
|
||||||
|
ActionFileNode actionFileNodeNew = ActionFileNode_CreateNormal(
|
||||||
|
fileNodeLeft, fileNodeRight);
|
||||||
|
|
||||||
|
if (!fileNodeLeft && !fileNodeRight) {
|
||||||
|
AccionFileNode_Destroy(actionFileNodeNew);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!fileNodeLeft && fileNodeRight) {
|
||||||
|
if (fileNodeRight->flags & FileFlag_Directory) {
|
||||||
|
// Directory
|
||||||
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_MakeLeftDirectory;
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
|
||||||
|
// Iterate childs
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
|
actionFileNodeQueue, AccionFileNode_SyncPair);
|
||||||
|
|
||||||
|
// Creatre new action for date copy
|
||||||
|
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
||||||
|
fileNodeRight);
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DateRightToLeft;
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// File
|
||||||
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_RightToLeft;
|
||||||
|
}
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fileNodeLeft && !fileNodeRight) {
|
||||||
|
if (fileNodeLeft->flags & FileFlag_Directory) {
|
||||||
|
// Directory
|
||||||
|
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_MakeRightDirectory;
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
|
||||||
|
// Iterate childs
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
|
actionFileNodeQueue, AccionFileNode_SyncPair);
|
||||||
|
|
||||||
|
// Create new action for date copy
|
||||||
|
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
||||||
|
fileNodeRight);
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// File
|
||||||
|
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||||
|
}
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fileNodeLeft && fileNodeRight) {
|
||||||
|
if ((fileNodeLeft->flags & FileFlag_Directory)
|
||||||
|
&& (fileNodeRight->flags & FileFlag_Directory))
|
||||||
|
{
|
||||||
|
// Directory
|
||||||
|
|
||||||
|
// Prepare action for directory pair
|
||||||
|
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime)) <= maxDeltaTime) { // aprox. equal
|
||||||
|
if (fileNodeRight->status == FileStatus_Deleted
|
||||||
|
&& fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
else if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||||
|
}
|
||||||
|
else if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DateRightToLeft;
|
||||||
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||||
|
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||||
|
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process child nodes
|
||||||
|
if (actionFileNodeNew->action == ActionFileCmp_DeleteRight
|
||||||
|
|| actionFileNodeNew->action == ActionFileCmp_DeleteLeft
|
||||||
|
|| (fileNodeLeft->status == FileStatus_Deleted
|
||||||
|
&& fileNodeRight->status == FileStatus_Deleted)) {
|
||||||
|
// Iterate child nodes for deletion
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
|
actionFileNodeQueue, AccionFileNode_DeletePair);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
|
actionFileNodeQueue, AccionFileNode_SyncPair);
|
||||||
|
}
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
else if ((fileNodeLeft->flags & FileFlag_Normal)
|
||||||
|
&& (fileNodeRight->flags & FileFlag_Normal))
|
||||||
|
{
|
||||||
|
// Files
|
||||||
|
|
||||||
|
// Prepare action for file pair
|
||||||
|
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime)) <= maxDeltaTime) { // aprox. equal
|
||||||
|
if (fileNodeRight->status == FileStatus_Deleted
|
||||||
|
&& fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
else if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||||
|
}
|
||||||
|
else if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
||||||
|
// FIXME: Check size to determine y further checks are necessary
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_RightToLeft;
|
||||||
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||||
|
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
||||||
|
// FIXME: Check size to determine y further checks are necessary
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||||
|
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// FIXME: !!!!!
|
||||||
|
// Directory vs File
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ActionFileNode ActionFileNode_BuildSync(FileNode izquierda, FileNode derecha) {
|
||||||
|
ActionFileNode actionFileNodeRoot = ActionFileNode_CreateNormal(izquierda,
|
||||||
|
derecha);
|
||||||
|
ActionFileNode actionFileNodeQueue = actionFileNodeRoot;
|
||||||
|
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
||||||
|
AccionFileNode_SyncPair);
|
||||||
|
return actionFileNodeRoot;
|
||||||
|
}
|
||||||
10
src/actionfilenodesync.h
Normal file
10
src/actionfilenodesync.h
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#ifndef _ACTIONFILENODESYNC_H_
|
||||||
|
#define _ACTIONFILENODESYNC_H_
|
||||||
|
|
||||||
|
#include "filenode.h"
|
||||||
|
#include "actionfilenode.h"
|
||||||
|
|
||||||
|
ActionFileNode ActionFileNode_BuildSync(FileNode fileNodeLeft,
|
||||||
|
FileNode fileNodeRight);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -6,7 +6,10 @@
|
|||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
#include "fileutil.h"
|
#include "fileutil.h"
|
||||||
#include "filenode.h"
|
#include "filenode.h"
|
||||||
#include "filenodecmp.h"
|
#include "actionfilenode.h"
|
||||||
|
#include "actionfilenodesync.h"
|
||||||
|
#include "actionfilenodecopy.h"
|
||||||
|
|
||||||
|
|
||||||
void Help(char *exe) {
|
void Help(char *exe) {
|
||||||
char exeFilename[MaxPath];
|
char exeFilename[MaxPath];
|
||||||
|
|||||||
Reference in New Issue
Block a user