Fixes on directory recreation.
Code formatting.
This commit is contained in:
65
.clang-format
Normal file
65
.clang-format
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
# BasedOnStyle: LLVM
|
||||||
|
AccessModifierOffset: -2
|
||||||
|
AlignAfterOpenBracket: true
|
||||||
|
AlignEscapedNewlinesLeft: false
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
AllowShortLoopsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: false
|
||||||
|
AlwaysBreakTemplateDeclarations: false
|
||||||
|
AlwaysBreakBeforeMultilineStrings: false
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BinPackParameters: true
|
||||||
|
BinPackArguments: true
|
||||||
|
ColumnLimit: 80
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
DerivePointerAlignment: false
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
IndentCaseLabels: false
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
IndentFunctionDeclarationAfterType: false
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 19
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 60
|
||||||
|
PointerAlignment: Right
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
Standard: Cpp11
|
||||||
|
IndentWidth: 4
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: true
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
DisableFormat: false
|
||||||
|
...
|
||||||
|
|
||||||
@@ -17,8 +17,8 @@ ActionFileNode ActionFileNode_Create() {
|
|||||||
ActionFileNode actionFileNodeFreeAux;
|
ActionFileNode actionFileNodeFreeAux;
|
||||||
int i;
|
int i;
|
||||||
// Allocate block
|
// Allocate block
|
||||||
actionFileNodeFreeAux = malloc(
|
actionFileNodeFreeAux =
|
||||||
sizeof(TActionFileNode) * AccionFileNode_Block);
|
malloc(sizeof(TActionFileNode) * AccionFileNode_Block);
|
||||||
if (actionFileNodeFreeAux == NULL) {
|
if (actionFileNodeFreeAux == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -48,8 +48,7 @@ void AccionFileNode_Destroy(ActionFileNode actionFileNode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ActionFileNode ActionFileNode_CreateNormal(FileNode fileNodeLeft,
|
ActionFileNode ActionFileNode_CreateNormal(FileNode fileNodeLeft,
|
||||||
FileNode fileNodeRight)
|
FileNode fileNodeRight) {
|
||||||
{
|
|
||||||
ActionFileNode actionFileNode;
|
ActionFileNode actionFileNode;
|
||||||
actionFileNode = ActionFileNode_Create();
|
actionFileNode = ActionFileNode_Create();
|
||||||
actionFileNode->action = ActionFileCmp_Nothing;
|
actionFileNode->action = ActionFileCmp_Nothing;
|
||||||
@@ -59,11 +58,9 @@ ActionFileNode ActionFileNode_CreateNormal(FileNode fileNodeLeft,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AccionFileNode_CompareChilds(
|
void AccionFileNode_CompareChilds(
|
||||||
ActionFileNode actionFileNodeRoot,
|
ActionFileNode actionFileNodeRoot, ActionFileNode *actionFileNodeQueue,
|
||||||
ActionFileNode *actionFileNodeQueue,
|
void (*CheckPair)(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||||
void(*CheckPair)(FileNode fileNodeLeft, FileNode fileNodeRight,
|
ActionFileNode *actionFileNodeQueue)) {
|
||||||
ActionFileNode *actionFileNodeQueue))
|
|
||||||
{
|
|
||||||
FileNode fileNodeLeft;
|
FileNode fileNodeLeft;
|
||||||
FileNode fileNodeRight;
|
FileNode fileNodeRight;
|
||||||
FileNode fileNodeRightQueue;
|
FileNode fileNodeRightQueue;
|
||||||
@@ -111,8 +108,7 @@ void AccionFileNode_CompareChilds(
|
|||||||
// Match, extract right child FileNode to the processed chain
|
// Match, extract right child FileNode to the processed chain
|
||||||
if (fileNodeRightPrevious) {
|
if (fileNodeRightPrevious) {
|
||||||
fileNodeRightPrevious->next = fileNodeRight->next;
|
fileNodeRightPrevious->next = fileNodeRight->next;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
fileNodeRightQueue = fileNodeRight->next;
|
fileNodeRightQueue = fileNodeRight->next;
|
||||||
}
|
}
|
||||||
fileNodeRight->next = fileNodeRightProcessed;
|
fileNodeRight->next = fileNodeRightProcessed;
|
||||||
@@ -120,8 +116,7 @@ void AccionFileNode_CompareChilds(
|
|||||||
|
|
||||||
CheckPair(fileNodeLeft, fileNodeRight, actionFileNodeQueue);
|
CheckPair(fileNodeLeft, fileNodeRight, actionFileNodeQueue);
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Next right child
|
// Next right child
|
||||||
fileNodeRightPrevious = fileNodeRight;
|
fileNodeRightPrevious = fileNodeRight;
|
||||||
fileNodeRight = fileNodeRight->next;
|
fileNodeRight = fileNodeRight->next;
|
||||||
@@ -146,8 +141,7 @@ void AccionFileNode_CompareChilds(
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ActionFileNode_Statistics(ActionFileNode actionFileNode,
|
int ActionFileNode_Statistics(ActionFileNode actionFileNode,
|
||||||
ActionQueueStatistics *statistics)
|
ActionQueueStatistics *statistics) {
|
||||||
{
|
|
||||||
statistics->readLeft = 0;
|
statistics->readLeft = 0;
|
||||||
statistics->writeLeft = 0;
|
statistics->writeLeft = 0;
|
||||||
statistics->readRight = 0;
|
statistics->readRight = 0;
|
||||||
@@ -198,12 +192,8 @@ int ActionFileNode_Statistics(ActionFileNode actionFileNode,
|
|||||||
|
|
||||||
actionFileNode = actionFileNode->next;
|
actionFileNode = actionFileNode->next;
|
||||||
}
|
}
|
||||||
return (
|
return (statistics->fullCopyCount + statistics->dateCopyCount +
|
||||||
statistics->fullCopyCount +
|
statistics->directoryCount + statistics->deleteCount);
|
||||||
statistics->dateCopyCount +
|
|
||||||
statistics->directoryCount +
|
|
||||||
statistics->deleteCount
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionFileNode_Print(ActionFileNode actionFileNode) {
|
void ActionFileNode_Print(ActionFileNode actionFileNode) {
|
||||||
@@ -211,14 +201,13 @@ void ActionFileNode_Print(ActionFileNode actionFileNode) {
|
|||||||
while (actionFileNode != NULL) {
|
while (actionFileNode != NULL) {
|
||||||
if (actionFileNode->left) {
|
if (actionFileNode->left) {
|
||||||
FileNode_GetFullPath(actionFileNode->left, "", showPath);
|
FileNode_GetFullPath(actionFileNode->left, "", showPath);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
FileNode_GetFullPath(actionFileNode->right, "", showPath);
|
FileNode_GetFullPath(actionFileNode->right, "", showPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (actionFileNode->action) {
|
switch (actionFileNode->action) {
|
||||||
case ActionFileCmp_Nothing:
|
case ActionFileCmp_Nothing:
|
||||||
//printff("%s == %s\n",pathIzq,pathDer);
|
// printff("%s == %s\n",pathIzq,pathDer);
|
||||||
break;
|
break;
|
||||||
case ActionFileCmp_LeftToRight:
|
case ActionFileCmp_LeftToRight:
|
||||||
Print(" => %s\n", showPath);
|
Print(" => %s\n", showPath);
|
||||||
@@ -259,84 +248,87 @@ void AccionFileNodeAux_CopyDate(char *pathOrig, char *pathDest) {
|
|||||||
void AccionFileNodeAux_Copy(char *pathOrig, char *pathDest) {
|
void AccionFileNodeAux_Copy(char *pathOrig, char *pathDest) {
|
||||||
if (File_Copy(pathOrig, pathDest)) {
|
if (File_Copy(pathOrig, pathDest)) {
|
||||||
AccionFileNodeAux_CopyDate(pathOrig, pathDest);
|
AccionFileNodeAux_CopyDate(pathOrig, pathDest);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
File_Delete(pathDest);
|
File_Delete(pathDest);
|
||||||
Print("Error Copying to: %s", pathDest);
|
Print("Error Copying to: %s\n", pathDest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void AccionFileNodeAux_Delete(char *pathOrig, char *pathDest) {
|
void AccionFileNodeAux_Delete(char *pathOrig, char *pathDest) {
|
||||||
if (File_IsDirectory(pathDest)) {
|
if (File_IsDirectory(pathDest)) {
|
||||||
File_DeleteDirectory(pathDest);
|
File_DeleteDirectory(pathDest);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
File_Delete(pathDest);
|
File_Delete(pathDest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void AccionFileNodeAux_MakeDir(char *pathOrig, char *pathDest) {
|
void AccionFileNodeAux_MakeDir(char *pathOrig, char *pathDest) {
|
||||||
if (File_MakeDirectory(pathDest) == 0) {
|
if (File_MakeDirectory(pathDest) == 0) {
|
||||||
Print("Error Making Directory: %s", pathDest);
|
Print("Error Making Directory: %s\n", pathDest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ActionFileNode_RunList(ActionFileNode actionFileNode, char *pathLeft,
|
int ActionFileNode_RunList(ActionFileNode actionFileNode, char *pathLeft,
|
||||||
char *pathRight)
|
char *pathRight) {
|
||||||
{
|
|
||||||
int numActions = 0;
|
int numActions = 0;
|
||||||
char fullPathLeft[MaxPath], fullPathRight[MaxPath], showPath[MaxPath];
|
char fullPathLeft[MaxPath], fullPathRight[MaxPath], showPath[MaxPath];
|
||||||
while (actionFileNode != NULL) {
|
while (actionFileNode != NULL) {
|
||||||
if (actionFileNode->left) {
|
if (actionFileNode->left) {
|
||||||
FileNode_GetFullPath(actionFileNode->left, pathLeft, fullPathLeft);
|
FileNode_GetFullPath(actionFileNode->left, pathLeft, fullPathLeft);
|
||||||
FileNode_GetFullPath(actionFileNode->left, "", showPath);
|
FileNode_GetFullPath(actionFileNode->left, "", showPath);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
FileNode_GetFullPath(actionFileNode->right, pathLeft, fullPathLeft);
|
FileNode_GetFullPath(actionFileNode->right, pathLeft, fullPathLeft);
|
||||||
FileNode_GetFullPath(actionFileNode->right, "", showPath);
|
FileNode_GetFullPath(actionFileNode->right, "", showPath);
|
||||||
}
|
}
|
||||||
if (actionFileNode->right) {
|
if (actionFileNode->right) {
|
||||||
FileNode_GetFullPath(actionFileNode->right, pathRight,
|
FileNode_GetFullPath(actionFileNode->right, pathRight,
|
||||||
fullPathRight);
|
fullPathRight);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
FileNode_GetFullPath(actionFileNode->left, pathRight,
|
FileNode_GetFullPath(actionFileNode->left, pathRight,
|
||||||
fullPathRight);
|
fullPathRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (actionFileNode->action) {
|
switch (actionFileNode->action) {
|
||||||
case ActionFileCmp_Nothing:
|
case ActionFileCmp_Nothing:
|
||||||
//printff("%s == %s\n",pathIzq,pathDer);
|
// printff("%s == %s\n",pathIzq,pathDer);
|
||||||
break;
|
break;
|
||||||
case ActionFileCmp_LeftToRight:
|
case ActionFileCmp_LeftToRight:
|
||||||
Print(" => %s\n", showPath);
|
Print(" => %s\n", showPath);
|
||||||
AccionFileNodeAux_Copy(fullPathLeft, fullPathRight); numActions++;
|
AccionFileNodeAux_Copy(fullPathLeft, fullPathRight);
|
||||||
|
numActions++;
|
||||||
break;
|
break;
|
||||||
case ActionFileCmp_RightToLeft:
|
case ActionFileCmp_RightToLeft:
|
||||||
Print(" <= %s\n", showPath);
|
Print(" <= %s\n", showPath);
|
||||||
AccionFileNodeAux_Copy(fullPathRight, fullPathLeft); numActions++;
|
AccionFileNodeAux_Copy(fullPathRight, fullPathLeft);
|
||||||
|
numActions++;
|
||||||
break;
|
break;
|
||||||
case ActionFileCmp_DeleteLeft:
|
case ActionFileCmp_DeleteLeft:
|
||||||
Print(" *- %s\n", showPath);
|
Print(" *- %s\n", showPath);
|
||||||
AccionFileNodeAux_Delete(fullPathRight, fullPathLeft); numActions++;
|
AccionFileNodeAux_Delete(fullPathRight, fullPathLeft);
|
||||||
|
numActions++;
|
||||||
break;
|
break;
|
||||||
case ActionFileCmp_DeleteRight:
|
case ActionFileCmp_DeleteRight:
|
||||||
Print(" -* %s\n", showPath);
|
Print(" -* %s\n", showPath);
|
||||||
AccionFileNodeAux_Delete(fullPathLeft, fullPathRight); numActions++;
|
AccionFileNodeAux_Delete(fullPathLeft, fullPathRight);
|
||||||
|
numActions++;
|
||||||
break;
|
break;
|
||||||
case ActionFileCmp_DateLeftToRight:
|
case ActionFileCmp_DateLeftToRight:
|
||||||
Print(" -> %s\n", showPath);
|
Print(" -> %s\n", showPath);
|
||||||
AccionFileNodeAux_CopyDate(fullPathLeft, fullPathRight); numActions++;
|
AccionFileNodeAux_CopyDate(fullPathLeft, fullPathRight);
|
||||||
|
numActions++;
|
||||||
break;
|
break;
|
||||||
case ActionFileCmp_DateRightToLeft:
|
case ActionFileCmp_DateRightToLeft:
|
||||||
Print(" <- %s\n", showPath);
|
Print(" <- %s\n", showPath);
|
||||||
AccionFileNodeAux_CopyDate(fullPathRight, fullPathLeft); numActions++;
|
AccionFileNodeAux_CopyDate(fullPathRight, fullPathLeft);
|
||||||
|
numActions++;
|
||||||
break;
|
break;
|
||||||
case ActionFileCmp_MakeRightDirectory:
|
case ActionFileCmp_MakeRightDirectory:
|
||||||
Print(" -D %s\n", showPath);
|
Print(" -D %s\n", showPath);
|
||||||
AccionFileNodeAux_MakeDir(fullPathLeft, fullPathRight); numActions++;
|
AccionFileNodeAux_MakeDir(fullPathLeft, fullPathRight);
|
||||||
|
numActions++;
|
||||||
break;
|
break;
|
||||||
case ActionFileCmp_MakeLeftDirectory:
|
case ActionFileCmp_MakeLeftDirectory:
|
||||||
Print(" D- %s\n", showPath);
|
Print(" D- %s\n", showPath);
|
||||||
AccionFileNodeAux_MakeDir(fullPathRight, fullPathLeft); numActions++;
|
AccionFileNodeAux_MakeDir(fullPathRight, fullPathLeft);
|
||||||
|
numActions++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,13 +341,14 @@ int ActionFileNode_RunList(ActionFileNode actionFileNode, char *pathLeft,
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Common utilities
|
// Common utilities
|
||||||
|
|
||||||
#define QueueNode(queue,node) (queue)->next = (node); (queue) = (node);
|
#define QueueNode(queue, node) \
|
||||||
|
(queue)->next = (node); \
|
||||||
|
(queue) = (node);
|
||||||
|
|
||||||
void AccionFileNode_DeletePair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
void AccionFileNode_DeletePair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||||
ActionFileNode *actionFileNodeQueue)
|
ActionFileNode *actionFileNodeQueue) {
|
||||||
{
|
ActionFileNode actionFileNodeNew =
|
||||||
ActionFileNode actionFileNodeNew = ActionFileNode_CreateNormal(
|
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||||
fileNodeLeft, fileNodeRight);
|
|
||||||
|
|
||||||
if (!fileNodeLeft && !fileNodeRight) {
|
if (!fileNodeLeft && !fileNodeRight) {
|
||||||
AccionFileNode_Destroy(actionFileNodeNew);
|
AccionFileNode_Destroy(actionFileNodeNew);
|
||||||
@@ -372,8 +365,7 @@ void AccionFileNode_DeletePair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|||||||
// Node delete action
|
// Node delete action
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
AccionFileNode_Destroy(actionFileNodeNew);
|
AccionFileNode_Destroy(actionFileNodeNew);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -388,14 +380,13 @@ void AccionFileNode_DeletePair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|||||||
// Node delete action
|
// Node delete action
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
AccionFileNode_Destroy(actionFileNodeNew);
|
AccionFileNode_Destroy(actionFileNodeNew);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fileNodeLeft && fileNodeRight) {
|
if (fileNodeLeft && fileNodeRight) {
|
||||||
if ((fileNodeLeft->flags & FileFlag_Directory)
|
if ((fileNodeLeft->flags & FileFlag_Directory) ||
|
||||||
|| (fileNodeRight->flags & FileFlag_Directory)) {
|
(fileNodeRight->flags & FileFlag_Directory)) {
|
||||||
// One is Directory
|
// One is Directory
|
||||||
|
|
||||||
// Iterate childs for deletion
|
// Iterate childs for deletion
|
||||||
@@ -411,8 +402,8 @@ void AccionFileNode_DeletePair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|||||||
}
|
}
|
||||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||||
if (!actionFileNodeNew) {
|
if (!actionFileNodeNew) {
|
||||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
actionFileNodeNew =
|
||||||
fileNodeRight);
|
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||||
}
|
}
|
||||||
// Right node delete action
|
// Right node delete action
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
|
|||||||
@@ -29,9 +29,8 @@ ActionFileNode ActionFileNode_CreateNormal(FileNode fileNodeLeft,
|
|||||||
FileNode fileNodeRight);
|
FileNode fileNodeRight);
|
||||||
|
|
||||||
void AccionFileNode_CompareChilds(
|
void AccionFileNode_CompareChilds(
|
||||||
ActionFileNode actionFileNodeRoot,
|
ActionFileNode actionFileNodeRoot, ActionFileNode *actionFileNodeQueue,
|
||||||
ActionFileNode *actionFileNodeQueue,
|
void (*CheckPair)(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||||
void(*CheckPair)(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|
||||||
ActionFileNode *actionFileNodeQueue));
|
ActionFileNode *actionFileNodeQueue));
|
||||||
|
|
||||||
typedef struct SActionQueueStatistics {
|
typedef struct SActionQueueStatistics {
|
||||||
|
|||||||
@@ -11,13 +11,14 @@
|
|||||||
|
|
||||||
#define MaxDeltaTime 0
|
#define MaxDeltaTime 0
|
||||||
|
|
||||||
#define QueueNode(queue,node) (queue)->next = (node); (queue) = (node);
|
#define QueueNode(queue, node) \
|
||||||
|
(queue)->next = (node); \
|
||||||
|
(queue) = (node);
|
||||||
|
|
||||||
void AccionFileNode_CopyPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
void AccionFileNode_CopyPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||||
ActionFileNode *actionFileNodeQueue)
|
ActionFileNode *actionFileNodeQueue) {
|
||||||
{
|
ActionFileNode actionFileNodeNew =
|
||||||
ActionFileNode actionFileNodeNew = ActionFileNode_CreateNormal(
|
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||||
fileNodeLeft, fileNodeRight);
|
|
||||||
|
|
||||||
if (!fileNodeLeft && !fileNodeRight) {
|
if (!fileNodeLeft && !fileNodeRight) {
|
||||||
AccionFileNode_Destroy(actionFileNodeNew);
|
AccionFileNode_Destroy(actionFileNodeNew);
|
||||||
@@ -31,8 +32,7 @@ void AccionFileNode_CopyPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|||||||
|
|
||||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
}
|
}
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
@@ -41,58 +41,59 @@ void AccionFileNode_CopyPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|||||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||||
if (fileNodeLeft->flags & FileFlag_Directory) {
|
if (fileNodeLeft->flags & FileFlag_Directory) {
|
||||||
actionFileNodeNew->action = ActionFileCmp_MakeRightDirectory;
|
actionFileNodeNew->action = ActionFileCmp_MakeRightDirectory;
|
||||||
(*actionFileNodeQueue)->next = actionFileNodeNew;
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
(*actionFileNodeQueue) = actionFileNodeNew;
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
actionFileNodeQueue, AccionFileNode_CopyPair);
|
actionFileNodeQueue,
|
||||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
AccionFileNode_CopyPair);
|
||||||
fileNodeRight);
|
actionFileNodeNew =
|
||||||
|
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
}
|
}
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
}
|
}
|
||||||
if (fileNodeLeft && fileNodeRight) {
|
if (fileNodeLeft && fileNodeRight) {
|
||||||
if ((fileNodeLeft->flags & FileFlag_Directory)
|
if ((fileNodeLeft->flags & FileFlag_Directory) ||
|
||||||
|| (fileNodeRight->flags & FileFlag_Directory))
|
(fileNodeRight->flags & FileFlag_Directory)) {
|
||||||
{
|
|
||||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
actionFileNodeQueue, AccionFileNode_CopyPair);
|
actionFileNodeNew->action =
|
||||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime))
|
ActionFileCmp_MakeRightDirectory;
|
||||||
<= MaxDeltaTime) { // appox. equal
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew = ActionFileNode_CreateNormal(
|
||||||
|
fileNodeLeft, fileNodeRight);
|
||||||
}
|
}
|
||||||
else {
|
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;
|
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
actionFileNodeQueue, AccionFileNode_DeletePair);
|
actionFileNodeQueue,
|
||||||
|
AccionFileNode_DeletePair);
|
||||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime))
|
if (abs((int)(fileNodeLeft->fileTime -
|
||||||
<= MaxDeltaTime)
|
fileNodeRight->fileTime)) <= MaxDeltaTime) {
|
||||||
{
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
}
|
}
|
||||||
@@ -104,8 +105,8 @@ void AccionFileNode_CopyPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|||||||
|
|
||||||
ActionFileNode ActionFileNode_BuildCopy(FileNode fileNodeLeft,
|
ActionFileNode ActionFileNode_BuildCopy(FileNode fileNodeLeft,
|
||||||
FileNode fileNodeRight) {
|
FileNode fileNodeRight) {
|
||||||
ActionFileNode actionFileNodeRoot = ActionFileNode_CreateNormal(
|
ActionFileNode actionFileNodeRoot =
|
||||||
fileNodeLeft, fileNodeRight);
|
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||||
ActionFileNode actionFileNodeQueue = actionFileNodeRoot;
|
ActionFileNode actionFileNodeQueue = actionFileNodeRoot;
|
||||||
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
||||||
AccionFileNode_CopyPair);
|
AccionFileNode_CopyPair);
|
||||||
|
|||||||
@@ -11,46 +11,44 @@
|
|||||||
|
|
||||||
#define MaxDeltaTime 0
|
#define MaxDeltaTime 0
|
||||||
|
|
||||||
#define QueueNode(queue,node) (queue)->next = (node); (queue) = (node);
|
#define QueueNode(queue, node) \
|
||||||
|
(queue)->next = (node); \
|
||||||
|
(queue) = (node);
|
||||||
|
|
||||||
void AccionFileNode_SyncPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
void AccionFileNode_SyncPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||||
ActionFileNode *actionFileNodeQueue)
|
ActionFileNode *actionFileNodeQueue) {
|
||||||
{
|
|
||||||
ActionFileNode actionFileNodeNew = ActionFileNode_CreateNormal(
|
|
||||||
fileNodeLeft, fileNodeRight);
|
|
||||||
|
|
||||||
if (!fileNodeLeft && !fileNodeRight) {
|
if (!fileNodeLeft && !fileNodeRight) {
|
||||||
AccionFileNode_Destroy(actionFileNodeNew);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ActionFileNode actionFileNodeNew =
|
||||||
|
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||||
|
|
||||||
if (!fileNodeLeft && fileNodeRight) {
|
if (!fileNodeLeft && fileNodeRight) {
|
||||||
if (fileNodeRight->flags & FileFlag_Directory) {
|
if (fileNodeRight->flags & FileFlag_Directory) {
|
||||||
// Directory
|
// Directory
|
||||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_MakeLeftDirectory;
|
actionFileNodeNew->action = ActionFileCmp_MakeLeftDirectory;
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
|
||||||
// Iterate childs
|
// Iterate childs
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
actionFileNodeQueue, AccionFileNode_SyncPair);
|
actionFileNodeQueue,
|
||||||
|
AccionFileNode_SyncPair);
|
||||||
|
|
||||||
// Creatre new action for date copy
|
// Create new action for date copy
|
||||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
actionFileNodeNew =
|
||||||
fileNodeRight);
|
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||||
actionFileNodeNew->action = ActionFileCmp_DateRightToLeft;
|
actionFileNodeNew->action = ActionFileCmp_DateRightToLeft;
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// File
|
// File
|
||||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_RightToLeft;
|
actionFileNodeNew->action = ActionFileCmp_RightToLeft;
|
||||||
}
|
}
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
@@ -62,111 +60,115 @@ void AccionFileNode_SyncPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|||||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_MakeRightDirectory;
|
actionFileNodeNew->action = ActionFileCmp_MakeRightDirectory;
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
|
||||||
// Iterate childs
|
// Iterate childs
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
actionFileNodeQueue, AccionFileNode_SyncPair);
|
actionFileNodeQueue,
|
||||||
|
AccionFileNode_SyncPair);
|
||||||
|
|
||||||
// Create new action for date copy
|
// Create new action for date copy
|
||||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
actionFileNodeNew =
|
||||||
fileNodeRight);
|
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// File
|
// File
|
||||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||||
}
|
}
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fileNodeLeft && fileNodeRight) {
|
if (fileNodeLeft && fileNodeRight) {
|
||||||
if ((fileNodeLeft->flags & FileFlag_Directory)
|
if ((fileNodeLeft->flags & FileFlag_Directory) &&
|
||||||
&& (fileNodeRight->flags & FileFlag_Directory))
|
(fileNodeRight->flags & FileFlag_Directory)) {
|
||||||
{
|
|
||||||
// Directory
|
// Directory
|
||||||
|
|
||||||
// Prepare action for directory pair
|
// Prepare action for directory pair
|
||||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime)) <= MaxDeltaTime) { // aprox. equal
|
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime)) <=
|
||||||
if (fileNodeRight->status == FileStatus_Deleted
|
MaxDeltaTime) { // aprox. equal
|
||||||
&& fileNodeLeft->status == FileStatus_Deleted) {
|
if (fileNodeRight->status == FileStatus_Deleted &&
|
||||||
|
fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
}
|
} else if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
else if (fileNodeRight->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||||
}
|
} else if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
else if (fileNodeLeft->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
}
|
}
|
||||||
|
} else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
||||||
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||||
|
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action =
|
||||||
|
ActionFileCmp_MakeLeftDirectory;
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
actionFileNodeNew = ActionFileNode_CreateNormal(
|
||||||
|
fileNodeLeft, fileNodeRight);
|
||||||
}
|
}
|
||||||
else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DateRightToLeft;
|
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) {
|
||||||
}
|
|
||||||
else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
|
||||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
|
actionFileNodeNew->action =
|
||||||
|
ActionFileCmp_MakeRightDirectory;
|
||||||
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
|
actionFileNodeNew = ActionFileNode_CreateNormal(
|
||||||
|
fileNodeLeft, fileNodeRight);
|
||||||
|
}
|
||||||
|
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process child nodes
|
// Process child nodes
|
||||||
if (actionFileNodeNew->action == ActionFileCmp_DeleteRight
|
if (actionFileNodeNew->action == ActionFileCmp_DeleteRight ||
|
||||||
|| actionFileNodeNew->action == ActionFileCmp_DeleteLeft
|
actionFileNodeNew->action == ActionFileCmp_DeleteLeft) {
|
||||||
|| (fileNodeLeft->status == FileStatus_Deleted
|
|
||||||
&& fileNodeRight->status == FileStatus_Deleted)) {
|
|
||||||
// Iterate child nodes for deletion
|
// Iterate child nodes for deletion
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
actionFileNodeQueue, AccionFileNode_DeletePair);
|
actionFileNodeQueue,
|
||||||
}
|
AccionFileNode_DeletePair);
|
||||||
else {
|
} else {
|
||||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||||
actionFileNodeQueue, AccionFileNode_SyncPair);
|
actionFileNodeQueue,
|
||||||
|
AccionFileNode_SyncPair);
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
}
|
} else if ((fileNodeLeft->flags & FileFlag_Normal) &&
|
||||||
else if ((fileNodeLeft->flags & FileFlag_Normal)
|
(fileNodeRight->flags & FileFlag_Normal)) {
|
||||||
&& (fileNodeRight->flags & FileFlag_Normal))
|
|
||||||
{
|
|
||||||
// Files
|
// Files
|
||||||
|
|
||||||
// Prepare action for file pair
|
// Prepare action for file pair
|
||||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime)) <= MaxDeltaTime) { // aprox. equal
|
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime)) <=
|
||||||
if (fileNodeRight->status == FileStatus_Deleted
|
MaxDeltaTime) { // aprox. equal
|
||||||
&& fileNodeLeft->status == FileStatus_Deleted) {
|
if (fileNodeRight->status == FileStatus_Deleted &&
|
||||||
|
fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
}
|
} else if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
else if (fileNodeRight->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||||
}
|
} else if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
else if (fileNodeLeft->status == FileStatus_Deleted) {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
}
|
}
|
||||||
}
|
} else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
||||||
else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
|
||||||
// FIXME: Check size to determine y further checks are necessary
|
// FIXME: Check size to determine y further checks are necessary
|
||||||
actionFileNodeNew->action = ActionFileCmp_RightToLeft;
|
actionFileNodeNew->action = ActionFileCmp_RightToLeft;
|
||||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||||
@@ -175,8 +177,7 @@ void AccionFileNode_SyncPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|||||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
||||||
else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
|
||||||
// FIXME: Check size to determine y further checks are necessary
|
// FIXME: Check size to determine y further checks are necessary
|
||||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||||
@@ -187,8 +188,7 @@ void AccionFileNode_SyncPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// FIXME: !!!!!
|
// FIXME: !!!!!
|
||||||
// Directory vs File
|
// Directory vs File
|
||||||
}
|
}
|
||||||
@@ -196,8 +196,8 @@ void AccionFileNode_SyncPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ActionFileNode ActionFileNode_BuildSync(FileNode izquierda, FileNode derecha) {
|
ActionFileNode ActionFileNode_BuildSync(FileNode izquierda, FileNode derecha) {
|
||||||
ActionFileNode actionFileNodeRoot = ActionFileNode_CreateNormal(izquierda,
|
ActionFileNode actionFileNodeRoot =
|
||||||
derecha);
|
ActionFileNode_CreateNormal(izquierda, derecha);
|
||||||
ActionFileNode actionFileNodeQueue = actionFileNodeRoot;
|
ActionFileNode actionFileNodeQueue = actionFileNodeRoot;
|
||||||
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
||||||
AccionFileNode_SyncPair);
|
AccionFileNode_SyncPair);
|
||||||
|
|||||||
@@ -28,12 +28,11 @@ void CRCTable_Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned long CRC_BufferInternal(unsigned char *buffer, unsigned long len,
|
unsigned long CRC_BufferInternal(unsigned char *buffer, unsigned long len,
|
||||||
unsigned long crc)
|
unsigned long crc) {
|
||||||
{
|
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
|
|
||||||
// Calculate CRC from buffer
|
// Calculate CRC from buffer
|
||||||
p = (unsigned char*)buffer;
|
p = (unsigned char *)buffer;
|
||||||
while (len-- != 0) {
|
while (len-- != 0) {
|
||||||
unsigned long termA = (crc >> 8) & 0x00FFFFFFL;
|
unsigned long termA = (crc >> 8) & 0x00FFFFFFL;
|
||||||
unsigned long termB = _crcTable[((int)crc ^ *p++) & 0xff];
|
unsigned long termB = _crcTable[((int)crc ^ *p++) & 0xff];
|
||||||
@@ -43,7 +42,8 @@ unsigned long CRC_BufferInternal(unsigned char *buffer, unsigned long len,
|
|||||||
return (crc);
|
return (crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long CRC_Buffer(unsigned char *buffer, unsigned long len, unsigned long crc) {
|
unsigned long CRC_Buffer(unsigned char *buffer, unsigned long len,
|
||||||
|
unsigned long crc) {
|
||||||
CRCTable_Init();
|
CRCTable_Init();
|
||||||
return (CRC_BufferInternal(buffer, len, crc));
|
return (CRC_BufferInternal(buffer, len, crc));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
unsigned long CRC_Buffer(unsigned char *buffer, unsigned long len, unsigned long crc);
|
unsigned long CRC_Buffer(unsigned char *buffer, unsigned long len,
|
||||||
|
unsigned long crc);
|
||||||
unsigned long CRC_File(FILE *file);
|
unsigned long CRC_File(FILE *file);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -95,10 +95,20 @@ void FileNode_AddChild(FileNode fileNode, FileNode fileNodeChild) {
|
|||||||
fileNodeChild->parent = fileNode;
|
fileNodeChild->parent = fileNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileNode FileNode_GetRoot(FileNode fileNode) {
|
||||||
|
FileNode fileNodeParent = fileNode->parent;
|
||||||
|
while (fileNodeParent != NULL && fileNodeParent->parent != NULL) {
|
||||||
|
fileNodeParent = fileNodeParent->parent;
|
||||||
|
}
|
||||||
|
return fileNodeParent;
|
||||||
|
}
|
||||||
|
|
||||||
void FileNode_SetStatusRec(FileNode fileNode, FileStatus status) {
|
void FileNode_SetStatusRec(FileNode fileNode, FileStatus status) {
|
||||||
FileNode fileNodeChild;
|
FileNode fileNodeChild;
|
||||||
if (status == FileStatus_Deleted && fileNode->status != status) {
|
if (status == FileStatus_Deleted && fileNode->status != status) {
|
||||||
fileNode->fileTime = Time_GetCurrentTime();
|
FileNode fileNodeRoot = FileNode_GetRoot(fileNode);
|
||||||
|
fileNode->fileTime = fileNodeRoot->fileTime;
|
||||||
|
;
|
||||||
fileNode->flags |= FileFlag_HasTime;
|
fileNode->flags |= FileFlag_HasTime;
|
||||||
}
|
}
|
||||||
fileNode->status = status;
|
fileNode->status = status;
|
||||||
@@ -113,8 +123,7 @@ void FileNode_GetPath_Rec(FileNode fileNode, char **pathNode) {
|
|||||||
if (fileNode->parent) {
|
if (fileNode->parent) {
|
||||||
pathNode[0] = fileNode->parent->name;
|
pathNode[0] = fileNode->parent->name;
|
||||||
FileNode_GetPath_Rec(fileNode->parent, pathNode + 1);
|
FileNode_GetPath_Rec(fileNode->parent, pathNode + 1);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
pathNode[0] = NULL;
|
pathNode[0] = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,7 +132,9 @@ char *FileNode_GetPath(FileNode fileNode, char *path) {
|
|||||||
char *pathNodes[MaxPathNodes];
|
char *pathNodes[MaxPathNodes];
|
||||||
int levels, i;
|
int levels, i;
|
||||||
char *pathPtr = tempPath;
|
char *pathPtr = tempPath;
|
||||||
if (path) { pathPtr = path; }
|
if (path) {
|
||||||
|
pathPtr = path;
|
||||||
|
}
|
||||||
|
|
||||||
FileNode_GetPath_Rec(fileNode, pathNodes);
|
FileNode_GetPath_Rec(fileNode, pathNodes);
|
||||||
levels = 0;
|
levels = 0;
|
||||||
@@ -195,8 +206,7 @@ void FileNode_SaveNode(FileNode fileNode, FILE *file) {
|
|||||||
fwrite((void *)&nameLen, sizeof(nameLen), 1, file);
|
fwrite((void *)&nameLen, sizeof(nameLen), 1, file);
|
||||||
if (nameLen > 0 && nameLen < MaxFilename) {
|
if (nameLen > 0 && nameLen < MaxFilename) {
|
||||||
fputs(fileNode->name, file);
|
fputs(fileNode->name, file);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +223,8 @@ void FileNode_SaveNode(FileNode fileNode, FILE *file) {
|
|||||||
|
|
||||||
// Write date
|
// Write date
|
||||||
if (fileNode->flags & FileFlag_HasTime) {
|
if (fileNode->flags & FileFlag_HasTime) {
|
||||||
fwrite((void *)&fileNode->fileTime, sizeof(fileNode->fileTime), 1, file);
|
fwrite((void *)&fileNode->fileTime, sizeof(fileNode->fileTime), 1,
|
||||||
|
file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write CRC
|
// Write CRC
|
||||||
@@ -224,7 +235,8 @@ void FileNode_SaveNode(FileNode fileNode, FILE *file) {
|
|||||||
// Write files of directory
|
// Write files of directory
|
||||||
if (fileNode->flags & FileFlag_Directory) {
|
if (fileNode->flags & FileFlag_Directory) {
|
||||||
FileNode fileNodeChild;
|
FileNode fileNodeChild;
|
||||||
fwrite((void *)&fileNode->childCount, sizeof(fileNode->childCount), 1, file);
|
fwrite((void *)&fileNode->childCount, sizeof(fileNode->childCount), 1,
|
||||||
|
file);
|
||||||
fileNodeChild = fileNode->child;
|
fileNodeChild = fileNode->child;
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
while (fileNodeChild) {
|
while (fileNodeChild) {
|
||||||
@@ -269,7 +281,7 @@ FileNode FileNode_LoadNode(FILE *file) {
|
|||||||
// Read name
|
// Read name
|
||||||
fread((void *)&nameLen, sizeof(nameLen), 1, file);
|
fread((void *)&nameLen, sizeof(nameLen), 1, file);
|
||||||
fileNode->name[0] = 0;
|
fileNode->name[0] = 0;
|
||||||
if (nameLen<0 || nameLen>MaxFilename) {
|
if (nameLen < 0 || nameLen > MaxFilename) {
|
||||||
FileNode_Delete(fileNode);
|
FileNode_Delete(fileNode);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -306,7 +318,8 @@ FileNode FileNode_LoadNode(FILE *file) {
|
|||||||
if (fileNode->flags & FileFlag_Directory) {
|
if (fileNode->flags & FileFlag_Directory) {
|
||||||
FileNode fileNodeChildAux = NULL;
|
FileNode fileNodeChildAux = NULL;
|
||||||
FileNode fileNodeChild;
|
FileNode fileNodeChild;
|
||||||
fread((void *)&fileNode->childCount, sizeof(fileNode->childCount), 1, file);
|
fread((void *)&fileNode->childCount, sizeof(fileNode->childCount), 1,
|
||||||
|
file);
|
||||||
for (i = 0; i < fileNode->childCount; i++) {
|
for (i = 0; i < fileNode->childCount; i++) {
|
||||||
fileNodeChild = FileNode_LoadNode(file);
|
fileNodeChild = FileNode_LoadNode(file);
|
||||||
if (fileNodeChild == NULL) {
|
if (fileNodeChild == NULL) {
|
||||||
@@ -316,8 +329,7 @@ FileNode FileNode_LoadNode(FILE *file) {
|
|||||||
fileNodeChild->parent = fileNode;
|
fileNodeChild->parent = fileNode;
|
||||||
if (!fileNodeChildAux) {
|
if (!fileNodeChildAux) {
|
||||||
fileNode->child = fileNodeChild;
|
fileNode->child = fileNodeChild;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
fileNodeChildAux->next = fileNodeChild;
|
fileNodeChildAux->next = fileNodeChild;
|
||||||
}
|
}
|
||||||
fileNodeChildAux = fileNodeChild;
|
fileNodeChildAux = fileNodeChild;
|
||||||
@@ -362,8 +374,7 @@ void FileNode_PrintNode(FileNode fileNode) {
|
|||||||
Print(FileNode_GetPath(fileNode, NULL));
|
Print(FileNode_GetPath(fileNode, NULL));
|
||||||
if (fileNode->flags & FileFlag_Normal) {
|
if (fileNode->flags & FileFlag_Normal) {
|
||||||
Print(" File");
|
Print(" File");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Print(" Dir");
|
Print(" Dir");
|
||||||
}
|
}
|
||||||
Print(" %d", fileNode->status);
|
Print(" %d", fileNode->status);
|
||||||
@@ -378,13 +389,15 @@ void FileNode_PrintNode(FileNode fileNode) {
|
|||||||
}
|
}
|
||||||
Print("\n");
|
Print("\n");
|
||||||
|
|
||||||
if (fileNode->flags&FileFlag_HasSize) {
|
if (fileNode->flags & FileFlag_HasSize) {
|
||||||
Print("\\-Size : %lld\n", fileNode->size);
|
Print("\\-Size : %lld\n", fileNode->size);
|
||||||
}
|
}
|
||||||
if (fileNode->flags&FileFlag_HasTime) {
|
if (fileNode->flags & FileFlag_HasTime) {
|
||||||
Print("\\-Date : "); FileTime_Print(fileNode->fileTime); Print("\n");
|
Print("\\-Date : ");
|
||||||
|
FileTime_Print(fileNode->fileTime);
|
||||||
|
Print("\n");
|
||||||
}
|
}
|
||||||
if (fileNode->flags&FileFlag_HasCRC) {
|
if (fileNode->flags & FileFlag_HasCRC) {
|
||||||
Print("\\-CRC : [%08X]\n", fileNode->crc);
|
Print("\\-CRC : [%08X]\n", fileNode->crc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,8 +413,7 @@ void FileNode_Print(FileNode fileNode) {
|
|||||||
|
|
||||||
if (fileNodeAux->child) {
|
if (fileNodeAux->child) {
|
||||||
fileNodeAux = fileNodeAux->child;
|
fileNodeAux = fileNodeAux->child;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
while (fileNodeAux->next == NULL) {
|
while (fileNodeAux->next == NULL) {
|
||||||
fileNodeAux = fileNodeAux->parent;
|
fileNodeAux = fileNodeAux->parent;
|
||||||
if (fileNodeAux == fileNode || fileNodeAux == NULL) {
|
if (fileNodeAux == fileNode || fileNodeAux == NULL) {
|
||||||
@@ -428,14 +440,15 @@ FileNode FileNode_Build(char *path) {
|
|||||||
// Create node
|
// Create node
|
||||||
fileNode = FileNode_Create();
|
fileNode = FileNode_Create();
|
||||||
File_GetName(path, fileNode->name);
|
File_GetName(path, fileNode->name);
|
||||||
|
fileNode->fileTime = Time_GetCurrentTime();
|
||||||
|
fileNode->flags |= FileFlag_HasTime;
|
||||||
|
|
||||||
if (File_IsDirectory(path)) {
|
if (File_IsDirectory(path)) {
|
||||||
// Get information data from directories, and child files
|
// Get information data from directories, and child files
|
||||||
fileNode->flags |= FileFlag_Directory;
|
fileNode->flags |= FileFlag_Directory;
|
||||||
FileNode_LoadTime(fileNode, path);
|
FileNode_LoadTime(fileNode, path);
|
||||||
File_IterateDir(path, FileNode_Build_Iterate, fileNode);
|
File_IterateDir(path, FileNode_Build_Iterate, fileNode);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Get information data from files
|
// Get information data from files
|
||||||
fileNode->flags |= FileFlag_Normal;
|
fileNode->flags |= FileFlag_Normal;
|
||||||
FileNode_LoadSizeAndTime(fileNode, path);
|
FileNode_LoadSizeAndTime(fileNode, path);
|
||||||
@@ -461,26 +474,22 @@ int FileNode_Build_Iterate(char *path, char *name, void *d) {
|
|||||||
int FileNode_Refresh_Iterate(char *path, char *name, void *d);
|
int FileNode_Refresh_Iterate(char *path, char *name, void *d);
|
||||||
|
|
||||||
FileNode FileNode_Refresh(FileNode fileNode, char *filePath) {
|
FileNode FileNode_Refresh(FileNode fileNode, char *filePath) {
|
||||||
|
if (!fileNode) {
|
||||||
|
Print("FileNode_Refresh: Error NULL FileNode\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!File_ExistsPath(filePath)) {
|
if (!File_ExistsPath(filePath)) {
|
||||||
// The file/directory has been deleted
|
// The file/directory has been deleted
|
||||||
if (!fileNode) {
|
|
||||||
fileNode = FileNode_Create();
|
|
||||||
File_GetName(filePath, fileNode->name);
|
|
||||||
}
|
|
||||||
FileNode_SetStatusRec(fileNode, FileStatus_Deleted);
|
FileNode_SetStatusRec(fileNode, FileStatus_Deleted);
|
||||||
return (fileNode);
|
return (fileNode);
|
||||||
}
|
}
|
||||||
if (!fileNode) {
|
|
||||||
// The file has been created
|
|
||||||
fileNode = FileNode_Build(filePath);
|
|
||||||
FileNode_SetStatusRec(fileNode, FileStatus_New);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Check modification
|
// Check modification
|
||||||
FileTime fileTime;
|
FileTime fileTime;
|
||||||
long long size;
|
long long size;
|
||||||
|
|
||||||
// Mark
|
// Remove mark
|
||||||
fileNode->flags &= ~FileFlag_MarkerForReview;
|
fileNode->flags &= ~FileFlag_MarkerForReview;
|
||||||
|
|
||||||
if (File_IsDirectory(filePath)) {
|
if (File_IsDirectory(filePath)) {
|
||||||
@@ -520,8 +529,7 @@ FileNode FileNode_Refresh(FileNode fileNode, char *filePath) {
|
|||||||
}
|
}
|
||||||
fileNodeChild = fileNodeChild->next;
|
fileNodeChild = fileNodeChild->next;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Comprar datos de los ficheros
|
// Comprar datos de los ficheros
|
||||||
if (!(fileNode->flags & FileFlag_Normal)) {
|
if (!(fileNode->flags & FileFlag_Normal)) {
|
||||||
fileNode->status = FileStatus_Modified;
|
fileNode->status = FileStatus_Modified;
|
||||||
@@ -544,7 +552,13 @@ FileNode FileNode_Refresh(FileNode fileNode, char *filePath) {
|
|||||||
fileNode->flags &= ~FileFlag_HasCRC;
|
fileNode->flags &= ~FileFlag_HasCRC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Save update time on root FileNode
|
||||||
|
if (fileNode->parent == NULL) {
|
||||||
|
fileNode->fileTime = Time_GetCurrentTime();
|
||||||
|
fileNode->flags |= FileFlag_HasTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (fileNode);
|
return (fileNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,10 +581,10 @@ int FileNode_Refresh_Iterate(char *path, char *name, void *d) {
|
|||||||
if (fileNodeChild) {
|
if (fileNodeChild) {
|
||||||
// Exists, Refresh
|
// Exists, Refresh
|
||||||
FileNode_Refresh(fileNodeChild, path);
|
FileNode_Refresh(fileNodeChild, path);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// New, Build
|
// New, Build
|
||||||
fileNodeChild = FileNode_Refresh(NULL, path);
|
fileNodeChild = FileNode_Build(path);
|
||||||
|
FileNode_SetStatusRec(fileNodeChild, FileStatus_New);
|
||||||
FileNode_AddChild(fileNode, fileNodeChild);
|
FileNode_AddChild(fileNode, fileNodeChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ FileNode FileNode_Create();
|
|||||||
FileNode FileNode_Copy(FileNode fileNode);
|
FileNode FileNode_Copy(FileNode fileNode);
|
||||||
void FileNode_Delete(FileNode fileNode);
|
void FileNode_Delete(FileNode fileNode);
|
||||||
void FileNode_AddChild(FileNode file, FileNode file2);
|
void FileNode_AddChild(FileNode file, FileNode file2);
|
||||||
|
FileNode FileNode_GetRoot(FileNode fileNode);
|
||||||
|
|
||||||
char *FileNode_GetFullPath(FileNode fileNode, char *basePath, char *path);
|
char *FileNode_GetFullPath(FileNode fileNode, char *basePath, char *path);
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
# define _WIN32_WINNT 0x0501
|
#define _WIN32_WINNT 0x0501
|
||||||
# include <direct.h>
|
#include <direct.h>
|
||||||
# include <windows.h>
|
#include <windows.h>
|
||||||
# include <io.h>
|
#include <io.h>
|
||||||
# include <stdio.h>
|
#include <stdio.h>
|
||||||
# include <signal.h>
|
#include <signal.h>
|
||||||
# include <fcntl.h>
|
#include <fcntl.h>
|
||||||
# include <sys/types.h>
|
#include <sys/types.h>
|
||||||
# include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
# include <time.h>
|
#include <time.h>
|
||||||
#else
|
#else
|
||||||
# include <stdio.h>
|
#include <stdio.h>
|
||||||
# include <string.h>
|
#include <string.h>
|
||||||
# include <sys/types.h>
|
#include <sys/types.h>
|
||||||
# include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
# include <time.h>
|
#include <time.h>
|
||||||
# include <utime.h>
|
#include <utime.h>
|
||||||
# include <dirent.h>
|
#include <dirent.h>
|
||||||
# include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
@@ -123,9 +123,8 @@ void FileTime_Print(FileTime fileTime) {
|
|||||||
struct tm *tms;
|
struct tm *tms;
|
||||||
|
|
||||||
tms = localtime((time_t *)&fileTime);
|
tms = localtime((time_t *)&fileTime);
|
||||||
Print("%04d-%02d-%02d %02d:%02d:%02d", tms->tm_year + 1900,
|
Print("%04d-%02d-%02d %02d:%02d:%02d", tms->tm_year + 1900, tms->tm_mon + 1,
|
||||||
tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min,
|
tms->tm_mday, tms->tm_hour, tms->tm_min, tms->tm_sec);
|
||||||
tms->tm_sec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -178,8 +177,7 @@ void File_GetName(char *path, char *name) {
|
|||||||
if (path[i] == '/' || path[i] == '\\') {
|
if (path[i] == '/' || path[i] == '\\') {
|
||||||
i++;
|
i++;
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -265,19 +263,16 @@ int File_IsFile(char *fileName) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
int File_MakeDirectory(char *path) {
|
int File_MakeDirectory(char *path) { return (CreateDirectory(path, NULL)); }
|
||||||
return (CreateDirectory(path, NULL));
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
int File_MakeDirectory(char *path) {
|
int File_MakeDirectory(char *path) { return (mkdir(path, 0777)); }
|
||||||
return (mkdir(path, 0777));
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
void File_IterateDir(char *path,
|
void File_IterateDir(char *path,
|
||||||
int(*func)(char *path, char *name, void *data), void *data) {
|
int (*func)(char *path, char *name, void *data),
|
||||||
|
void *data) {
|
||||||
intptr_t handle;
|
intptr_t handle;
|
||||||
struct _finddata_t fileinfo;
|
struct _finddata_t fileinfo;
|
||||||
char f_path[MaxPath];
|
char f_path[MaxPath];
|
||||||
@@ -305,7 +300,8 @@ void File_IterateDir(char *path,
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
void File_IterateDir(char *path,
|
void File_IterateDir(char *path,
|
||||||
int(*func)(char *path, char *name, void *data), void *data) {
|
int (*func)(char *path, char *name, void *data),
|
||||||
|
void *data) {
|
||||||
DIR *directorio;
|
DIR *directorio;
|
||||||
struct dirent *entidad_dir;
|
struct dirent *entidad_dir;
|
||||||
char f_path[MaxPath];
|
char f_path[MaxPath];
|
||||||
@@ -320,9 +316,8 @@ void File_IterateDir(char *path,
|
|||||||
do {
|
do {
|
||||||
entidad_dir = readdir(directorio);
|
entidad_dir = readdir(directorio);
|
||||||
if (entidad_dir != NULL) {
|
if (entidad_dir != NULL) {
|
||||||
if (strcmp(entidad_dir->d_name, ".")
|
if (strcmp(entidad_dir->d_name, ".") &&
|
||||||
&& strcmp(entidad_dir->d_name, ".."))
|
strcmp(entidad_dir->d_name, "..")) {
|
||||||
{
|
|
||||||
// Each item
|
// Each item
|
||||||
snprintf(f_path, MaxPath, "%s/%s", path, entidad_dir->d_name);
|
snprintf(f_path, MaxPath, "%s/%s", path, entidad_dir->d_name);
|
||||||
fin = func(f_path, entidad_dir->d_name, data);
|
fin = func(f_path, entidad_dir->d_name, data);
|
||||||
@@ -365,7 +360,7 @@ int File_Copy(const char *pathOrig, const char *pathDest) {
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = malloc(sizeof(char)*MaxBuffer);
|
buffer = malloc(sizeof(char) * MaxBuffer);
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@@ -387,8 +382,14 @@ int File_Copy(const char *pathOrig, const char *pathDest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (fOrig != NULL) { fclose(fOrig); }
|
if (fOrig != NULL) {
|
||||||
if (fDest != NULL) { fclose(fDest); }
|
fclose(fOrig);
|
||||||
if (buffer != NULL) { free(buffer); }
|
}
|
||||||
|
if (fDest != NULL) {
|
||||||
|
fclose(fDest);
|
||||||
|
}
|
||||||
|
if (buffer != NULL) {
|
||||||
|
free(buffer);
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -45,7 +45,8 @@ int File_IsFile(char *path);
|
|||||||
int File_MakeDirectory(char *path);
|
int File_MakeDirectory(char *path);
|
||||||
|
|
||||||
void File_IterateDir(char *path,
|
void File_IterateDir(char *path,
|
||||||
int(*func)(char *path, char *name, void *data), void *data);
|
int (*func)(char *path, char *name, void *data),
|
||||||
|
void *data);
|
||||||
|
|
||||||
void File_Delete(char *path);
|
void File_Delete(char *path);
|
||||||
void File_DeleteDirectory(char *path);
|
void File_DeleteDirectory(char *path);
|
||||||
|
|||||||
89
src/main.c
89
src/main.c
@@ -42,7 +42,8 @@ int main(int argc, char *argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Print("\n================================ FileSync ===================================\n");
|
Print("\n================================ FileSync "
|
||||||
|
"===================================\n");
|
||||||
if (!strcmp(argv[1], "info") && argc >= 3) {
|
if (!strcmp(argv[1], "info") && argc >= 3) {
|
||||||
// Informacion de ficheros
|
// Informacion de ficheros
|
||||||
int i;
|
int i;
|
||||||
@@ -53,18 +54,18 @@ int main(int argc, char *argv[]) {
|
|||||||
FileNode_PrintNode(fileNode);
|
FileNode_PrintNode(fileNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (!strcmp(argv[1], "scan") && argc == 4) {
|
||||||
else if (!strcmp(argv[1], "scan") && argc == 4) {
|
|
||||||
// Scan directory information tree and save
|
// Scan directory information tree and save
|
||||||
long long tScan = Time_GetTime();
|
long long tScan = Time_GetTime();
|
||||||
FileNode fileNode;
|
FileNode fileNode;
|
||||||
Print("Building FileNode..\n");
|
Print("Building FileNode..\n");
|
||||||
fileNode = FileNode_Build(argv[2]);
|
fileNode = FileNode_Build(argv[2]);
|
||||||
tScan = Time_GetTime() - tScan;
|
tScan = Time_GetTime() - tScan;
|
||||||
Print("\ttScan :"); PrintElapsedTime(tScan); Print("\n");
|
Print("\ttScan :");
|
||||||
|
PrintElapsedTime(tScan);
|
||||||
|
Print("\n");
|
||||||
FileNode_Save(fileNode, argv[3]);
|
FileNode_Save(fileNode, argv[3]);
|
||||||
}
|
} else if (!strcmp(argv[1], "rescan") && argc == 4) {
|
||||||
else if (!strcmp(argv[1], "rescan") && argc == 4) {
|
|
||||||
// Scan directory information and save tree
|
// Scan directory information and save tree
|
||||||
FileNode fileNode;
|
FileNode fileNode;
|
||||||
Print("Loading FileNode..\n");
|
Print("Loading FileNode..\n");
|
||||||
@@ -74,26 +75,27 @@ int main(int argc, char *argv[]) {
|
|||||||
long long tScan = Time_GetTime();
|
long long tScan = Time_GetTime();
|
||||||
fileNode = FileNode_Refresh(fileNode, argv[2]);
|
fileNode = FileNode_Refresh(fileNode, argv[2]);
|
||||||
tScan = Time_GetTime() - tScan;
|
tScan = Time_GetTime() - tScan;
|
||||||
Print("\ttScan :"); PrintElapsedTime(tScan); Print("\n");
|
Print("\ttScan :");
|
||||||
|
PrintElapsedTime(tScan);
|
||||||
|
Print("\n");
|
||||||
FileNode_Save(fileNode, argv[3]);
|
FileNode_Save(fileNode, argv[3]);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Print("Building FileNode..\n");
|
Print("Building FileNode..\n");
|
||||||
long long tScan = Time_GetTime();
|
long long tScan = Time_GetTime();
|
||||||
fileNode = FileNode_Build(argv[2]);
|
fileNode = FileNode_Build(argv[2]);
|
||||||
tScan = Time_GetTime() - tScan;
|
tScan = Time_GetTime() - tScan;
|
||||||
Print("\ttScan :"); PrintElapsedTime(tScan); Print("\n");
|
Print("\ttScan :");
|
||||||
|
PrintElapsedTime(tScan);
|
||||||
|
Print("\n");
|
||||||
FileNode_Save(fileNode, argv[3]);
|
FileNode_Save(fileNode, argv[3]);
|
||||||
}
|
}
|
||||||
}
|
} else if (!strcmp(argv[1], "read") && argc >= 3) {
|
||||||
else if (!strcmp(argv[1], "read") && argc >= 3) {
|
|
||||||
// Read information tree from file
|
// Read information tree from file
|
||||||
FileNode fileNode;
|
FileNode fileNode;
|
||||||
fileNode = FileNode_Load(argv[2]);
|
fileNode = FileNode_Load(argv[2]);
|
||||||
if (fileNode)
|
if (fileNode)
|
||||||
FileNode_Print(fileNode);
|
FileNode_Print(fileNode);
|
||||||
}
|
} else if (!strcmp(argv[1], "dir") && argc == 3) {
|
||||||
else if (!strcmp(argv[1], "dir") && argc == 3) {
|
|
||||||
// Read directory information tree
|
// Read directory information tree
|
||||||
char *path = argv[2];
|
char *path = argv[2];
|
||||||
FileNode fileNode;
|
FileNode fileNode;
|
||||||
@@ -102,44 +104,34 @@ int main(int argc, char *argv[]) {
|
|||||||
if (fileNode) {
|
if (fileNode) {
|
||||||
FileNode_Print(fileNode);
|
FileNode_Print(fileNode);
|
||||||
}
|
}
|
||||||
}
|
} else if (!strcmp(argv[1], "check") && argc == 3) {
|
||||||
else if (!strcmp(argv[1], "check") && argc == 3) {
|
|
||||||
// Read directory information tree
|
// Read directory information tree
|
||||||
char *path = argv[2];
|
char *path = argv[2];
|
||||||
FileNode fileNode;
|
FileNode fileNode;
|
||||||
|
|
||||||
fileNode = CheckDir(path, 1);
|
fileNode = CheckDir(path, 1);
|
||||||
}
|
} else if (argc == 4) {
|
||||||
else if (argc == 4) {
|
|
||||||
char *cmd = argv[1];
|
char *cmd = argv[1];
|
||||||
char *pathLeft = argv[2];
|
char *pathLeft = argv[2];
|
||||||
char *pathRight = argv[3];
|
char *pathRight = argv[3];
|
||||||
if (!strcmp(cmd, "sync")) {
|
if (!strcmp(cmd, "sync")) {
|
||||||
Sync(pathLeft, pathRight, 1, 0);
|
Sync(pathLeft, pathRight, 1, 0);
|
||||||
}
|
} else if (!strcmp(cmd, "resync")) {
|
||||||
else if (!strcmp(cmd, "resync")) {
|
|
||||||
Sync(pathLeft, pathRight, 0, 0);
|
Sync(pathLeft, pathRight, 0, 0);
|
||||||
}
|
} else if (!strcmp(cmd, "synctest")) {
|
||||||
else if (!strcmp(cmd, "synctest")) {
|
|
||||||
Sync(pathLeft, pathRight, 1, 1);
|
Sync(pathLeft, pathRight, 1, 1);
|
||||||
}
|
} else if (!strcmp(cmd, "resynctest")) {
|
||||||
else if (!strcmp(cmd, "resynctest")) {
|
|
||||||
Sync(pathLeft, pathRight, 0, 1);
|
Sync(pathLeft, pathRight, 0, 1);
|
||||||
}
|
} else if (!strcmp(cmd, "copy")) {
|
||||||
else if (!strcmp(cmd, "copy")) {
|
|
||||||
Copy(pathLeft, pathRight, 1, 0);
|
Copy(pathLeft, pathRight, 1, 0);
|
||||||
}
|
} else if (!strcmp(cmd, "recopy")) {
|
||||||
else if (!strcmp(cmd, "recopy")) {
|
|
||||||
Copy(pathLeft, pathRight, 0, 0);
|
Copy(pathLeft, pathRight, 0, 0);
|
||||||
}
|
} else if (!strcmp(cmd, "copytest")) {
|
||||||
else if (!strcmp(cmd, "copytest")) {
|
|
||||||
Copy(pathLeft, pathRight, 1, 1);
|
Copy(pathLeft, pathRight, 1, 1);
|
||||||
}
|
} else if (!strcmp(cmd, "recopytest")) {
|
||||||
else if (!strcmp(cmd, "recopytest")) {
|
|
||||||
Copy(pathLeft, pathRight, 0, 1);
|
Copy(pathLeft, pathRight, 0, 1);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Help(argv[0]);
|
Help(argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,22 +143,22 @@ FileNode CheckDir(char *path, int recheck) {
|
|||||||
FileNode fileNode;
|
FileNode fileNode;
|
||||||
|
|
||||||
// Check directory
|
// Check directory
|
||||||
snprintf(dirNodesFile, MaxPath, "%s/"FileNode_Filename, path);
|
snprintf(dirNodesFile, MaxPath, "%s/" FileNode_Filename, path);
|
||||||
if (recheck) {
|
if (recheck) {
|
||||||
Print("Checking Directory.. %s\n", path);
|
Print("Checking Directory.. %s\n", path);
|
||||||
long long tScan = Time_GetTime();
|
long long tScan = Time_GetTime();
|
||||||
fileNode = FileNode_Load(dirNodesFile);
|
fileNode = FileNode_Load(dirNodesFile);
|
||||||
if (fileNode) {
|
if (fileNode) {
|
||||||
fileNode = FileNode_Refresh(fileNode, path);
|
fileNode = FileNode_Refresh(fileNode, path);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
fileNode = FileNode_Build(path);
|
fileNode = FileNode_Build(path);
|
||||||
}
|
}
|
||||||
tScan = Time_GetTime() - tScan;
|
tScan = Time_GetTime() - tScan;
|
||||||
Print("\ttScan :"); PrintElapsedTime(tScan); Print("\n");
|
Print("\ttScan :");
|
||||||
|
PrintElapsedTime(tScan);
|
||||||
|
Print("\n");
|
||||||
FileNode_Save(fileNode, dirNodesFile);
|
FileNode_Save(fileNode, dirNodesFile);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Print("Loading Directory.. %s\n", path);
|
Print("Loading Directory.. %s\n", path);
|
||||||
fileNode = FileNode_Load(dirNodesFile);
|
fileNode = FileNode_Load(dirNodesFile);
|
||||||
if (!fileNode) {
|
if (!fileNode) {
|
||||||
@@ -185,8 +177,7 @@ void PrintStatistics(ActionFileNode actionFileNode) {
|
|||||||
}
|
}
|
||||||
Print("Statistics\n");
|
Print("Statistics\n");
|
||||||
|
|
||||||
Print(" % 8s % 8s % 8s\n",
|
Print(" % 8s % 8s % 8s\n", "Read", "Write", "Delete");
|
||||||
"Read", "Write", "Delete");
|
|
||||||
Print("Left :");
|
Print("Left :");
|
||||||
PrintDataSize(statistics.readLeft);
|
PrintDataSize(statistics.readLeft);
|
||||||
PrintDataSize(statistics.writeLeft);
|
PrintDataSize(statistics.writeLeft);
|
||||||
@@ -233,14 +224,15 @@ int Sync(char *pathLeft, char *pathRight, int reCheck, int dryRun) {
|
|||||||
ActionFileNode actionFileNode = NULL;
|
ActionFileNode actionFileNode = NULL;
|
||||||
actionFileNode = ActionFileNode_BuildSync(fileNodeLeft, fileNodeRight);
|
actionFileNode = ActionFileNode_BuildSync(fileNodeLeft, fileNodeRight);
|
||||||
tBuild = Time_GetTime() - tBuild;
|
tBuild = Time_GetTime() - tBuild;
|
||||||
Print("\ttBuild:"); PrintElapsedTime(tBuild); Print("\n");
|
Print("\ttBuild:");
|
||||||
|
PrintElapsedTime(tBuild);
|
||||||
|
Print("\n");
|
||||||
|
|
||||||
if (dryRun) {
|
if (dryRun) {
|
||||||
// Show action list
|
// Show action list
|
||||||
ActionFileNode_Print(actionFileNode);
|
ActionFileNode_Print(actionFileNode);
|
||||||
PrintStatistics(actionFileNode);
|
PrintStatistics(actionFileNode);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Run action list
|
// Run action list
|
||||||
if (ActionFileNode_RunList(actionFileNode, pathLeft, pathRight)) {
|
if (ActionFileNode_RunList(actionFileNode, pathLeft, pathRight)) {
|
||||||
CheckDir(pathLeft, reCheck);
|
CheckDir(pathLeft, reCheck);
|
||||||
@@ -279,14 +271,15 @@ int Copy(char *pathLeft, char *pathRight, int reCheck, int dryRun) {
|
|||||||
ActionFileNode actionFileNode = NULL;
|
ActionFileNode actionFileNode = NULL;
|
||||||
actionFileNode = ActionFileNode_BuildCopy(fileNodeLeft, fileNodeRight);
|
actionFileNode = ActionFileNode_BuildCopy(fileNodeLeft, fileNodeRight);
|
||||||
tBuild = Time_GetTime() - tBuild;
|
tBuild = Time_GetTime() - tBuild;
|
||||||
Print("\ttBuild:"); PrintElapsedTime(tBuild); Print("\n");
|
Print("\ttBuild:");
|
||||||
|
PrintElapsedTime(tBuild);
|
||||||
|
Print("\n");
|
||||||
|
|
||||||
if (dryRun) {
|
if (dryRun) {
|
||||||
// Show action list
|
// Show action list
|
||||||
ActionFileNode_Print(actionFileNode);
|
ActionFileNode_Print(actionFileNode);
|
||||||
PrintStatistics(actionFileNode);
|
PrintStatistics(actionFileNode);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Run action list
|
// Run action list
|
||||||
if (ActionFileNode_RunList(actionFileNode, pathLeft, pathRight)) {
|
if (ActionFileNode_RunList(actionFileNode, pathLeft, pathRight)) {
|
||||||
CheckDir(pathLeft, reCheck);
|
CheckDir(pathLeft, reCheck);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ long long Time_GetTime() {
|
|||||||
QueryPerformanceFrequency(&freq);
|
QueryPerformanceFrequency(&freq);
|
||||||
QueryPerformanceCounter(&tim);
|
QueryPerformanceCounter(&tim);
|
||||||
microt = (tim.QuadPart * 1000000) / freq.QuadPart;
|
microt = (tim.QuadPart * 1000000) / freq.QuadPart;
|
||||||
return(microt);
|
return (microt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -51,8 +51,7 @@ void Time_Pause(int pausa) {
|
|||||||
diff = tend - t;
|
diff = tend - t;
|
||||||
if (diff > 1000) {
|
if (diff > 1000) {
|
||||||
Sleep((int)diff / 1000);
|
Sleep((int)diff / 1000);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Sleep(0);
|
Sleep(0);
|
||||||
}
|
}
|
||||||
t = Time_GetTime();
|
t = Time_GetTime();
|
||||||
@@ -68,7 +67,7 @@ long long Time_GetTime() {
|
|||||||
long long usecs;
|
long long usecs;
|
||||||
gettimeofday(&t, NULL);
|
gettimeofday(&t, NULL);
|
||||||
usecs = (t.tv_sec * 1000000ll) + (t.tv_usec);
|
usecs = (t.tv_sec * 1000000ll) + (t.tv_usec);
|
||||||
return(usecs);
|
return (usecs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
@@ -154,5 +153,5 @@ int Print(char *fmt, ...) {
|
|||||||
|
|
||||||
// Flush
|
// Flush
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
return(n);
|
return (n);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user