Fixes on directory recreation.
Code formatting.
This commit is contained in:
@@ -17,8 +17,8 @@ ActionFileNode ActionFileNode_Create() {
|
||||
ActionFileNode actionFileNodeFreeAux;
|
||||
int i;
|
||||
// Allocate block
|
||||
actionFileNodeFreeAux = malloc(
|
||||
sizeof(TActionFileNode) * AccionFileNode_Block);
|
||||
actionFileNodeFreeAux =
|
||||
malloc(sizeof(TActionFileNode) * AccionFileNode_Block);
|
||||
if (actionFileNodeFreeAux == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -48,8 +48,7 @@ void AccionFileNode_Destroy(ActionFileNode actionFileNode) {
|
||||
}
|
||||
|
||||
ActionFileNode ActionFileNode_CreateNormal(FileNode fileNodeLeft,
|
||||
FileNode fileNodeRight)
|
||||
{
|
||||
FileNode fileNodeRight) {
|
||||
ActionFileNode actionFileNode;
|
||||
actionFileNode = ActionFileNode_Create();
|
||||
actionFileNode->action = ActionFileCmp_Nothing;
|
||||
@@ -59,11 +58,9 @@ ActionFileNode ActionFileNode_CreateNormal(FileNode fileNodeLeft,
|
||||
}
|
||||
|
||||
void AccionFileNode_CompareChilds(
|
||||
ActionFileNode actionFileNodeRoot,
|
||||
ActionFileNode *actionFileNodeQueue,
|
||||
void(*CheckPair)(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
ActionFileNode *actionFileNodeQueue))
|
||||
{
|
||||
ActionFileNode actionFileNodeRoot, ActionFileNode *actionFileNodeQueue,
|
||||
void (*CheckPair)(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
ActionFileNode *actionFileNodeQueue)) {
|
||||
FileNode fileNodeLeft;
|
||||
FileNode fileNodeRight;
|
||||
FileNode fileNodeRightQueue;
|
||||
@@ -111,8 +108,7 @@ void AccionFileNode_CompareChilds(
|
||||
// Match, extract right child FileNode to the processed chain
|
||||
if (fileNodeRightPrevious) {
|
||||
fileNodeRightPrevious->next = fileNodeRight->next;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fileNodeRightQueue = fileNodeRight->next;
|
||||
}
|
||||
fileNodeRight->next = fileNodeRightProcessed;
|
||||
@@ -120,8 +116,7 @@ void AccionFileNode_CompareChilds(
|
||||
|
||||
CheckPair(fileNodeLeft, fileNodeRight, actionFileNodeQueue);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Next right child
|
||||
fileNodeRightPrevious = fileNodeRight;
|
||||
fileNodeRight = fileNodeRight->next;
|
||||
@@ -146,8 +141,7 @@ void AccionFileNode_CompareChilds(
|
||||
}
|
||||
|
||||
int ActionFileNode_Statistics(ActionFileNode actionFileNode,
|
||||
ActionQueueStatistics *statistics)
|
||||
{
|
||||
ActionQueueStatistics *statistics) {
|
||||
statistics->readLeft = 0;
|
||||
statistics->writeLeft = 0;
|
||||
statistics->readRight = 0;
|
||||
@@ -198,12 +192,8 @@ int ActionFileNode_Statistics(ActionFileNode actionFileNode,
|
||||
|
||||
actionFileNode = actionFileNode->next;
|
||||
}
|
||||
return (
|
||||
statistics->fullCopyCount +
|
||||
statistics->dateCopyCount +
|
||||
statistics->directoryCount +
|
||||
statistics->deleteCount
|
||||
);
|
||||
return (statistics->fullCopyCount + statistics->dateCopyCount +
|
||||
statistics->directoryCount + statistics->deleteCount);
|
||||
}
|
||||
|
||||
void ActionFileNode_Print(ActionFileNode actionFileNode) {
|
||||
@@ -211,14 +201,13 @@ void ActionFileNode_Print(ActionFileNode actionFileNode) {
|
||||
while (actionFileNode != NULL) {
|
||||
if (actionFileNode->left) {
|
||||
FileNode_GetFullPath(actionFileNode->left, "", showPath);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
FileNode_GetFullPath(actionFileNode->right, "", showPath);
|
||||
}
|
||||
|
||||
switch (actionFileNode->action) {
|
||||
case ActionFileCmp_Nothing:
|
||||
//printff("%s == %s\n",pathIzq,pathDer);
|
||||
// printff("%s == %s\n",pathIzq,pathDer);
|
||||
break;
|
||||
case ActionFileCmp_LeftToRight:
|
||||
Print(" => %s\n", showPath);
|
||||
@@ -259,103 +248,107 @@ void AccionFileNodeAux_CopyDate(char *pathOrig, char *pathDest) {
|
||||
void AccionFileNodeAux_Copy(char *pathOrig, char *pathDest) {
|
||||
if (File_Copy(pathOrig, pathDest)) {
|
||||
AccionFileNodeAux_CopyDate(pathOrig, pathDest);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
File_Delete(pathDest);
|
||||
Print("Error Copying to: %s", pathDest);
|
||||
Print("Error Copying to: %s\n", pathDest);
|
||||
}
|
||||
}
|
||||
void AccionFileNodeAux_Delete(char *pathOrig, char *pathDest) {
|
||||
if (File_IsDirectory(pathDest)) {
|
||||
File_DeleteDirectory(pathDest);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
File_Delete(pathDest);
|
||||
}
|
||||
}
|
||||
void AccionFileNodeAux_MakeDir(char *pathOrig, char *pathDest) {
|
||||
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,
|
||||
char *pathRight)
|
||||
{
|
||||
char *pathRight) {
|
||||
int numActions = 0;
|
||||
char fullPathLeft[MaxPath], fullPathRight[MaxPath], showPath[MaxPath];
|
||||
while (actionFileNode != NULL) {
|
||||
if (actionFileNode->left) {
|
||||
FileNode_GetFullPath(actionFileNode->left, pathLeft, fullPathLeft);
|
||||
FileNode_GetFullPath(actionFileNode->left, "", showPath);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
FileNode_GetFullPath(actionFileNode->right, pathLeft, fullPathLeft);
|
||||
FileNode_GetFullPath(actionFileNode->right, "", showPath);
|
||||
}
|
||||
if (actionFileNode->right) {
|
||||
FileNode_GetFullPath(actionFileNode->right, pathRight,
|
||||
fullPathRight);
|
||||
}
|
||||
else {
|
||||
fullPathRight);
|
||||
} else {
|
||||
FileNode_GetFullPath(actionFileNode->left, pathRight,
|
||||
fullPathRight);
|
||||
fullPathRight);
|
||||
}
|
||||
|
||||
switch (actionFileNode->action) {
|
||||
case ActionFileCmp_Nothing:
|
||||
//printff("%s == %s\n",pathIzq,pathDer);
|
||||
// printff("%s == %s\n",pathIzq,pathDer);
|
||||
break;
|
||||
case ActionFileCmp_LeftToRight:
|
||||
Print(" => %s\n", showPath);
|
||||
AccionFileNodeAux_Copy(fullPathLeft, fullPathRight); numActions++;
|
||||
AccionFileNodeAux_Copy(fullPathLeft, fullPathRight);
|
||||
numActions++;
|
||||
break;
|
||||
case ActionFileCmp_RightToLeft:
|
||||
Print(" <= %s\n", showPath);
|
||||
AccionFileNodeAux_Copy(fullPathRight, fullPathLeft); numActions++;
|
||||
AccionFileNodeAux_Copy(fullPathRight, fullPathLeft);
|
||||
numActions++;
|
||||
break;
|
||||
case ActionFileCmp_DeleteLeft:
|
||||
Print(" *- %s\n", showPath);
|
||||
AccionFileNodeAux_Delete(fullPathRight, fullPathLeft); numActions++;
|
||||
AccionFileNodeAux_Delete(fullPathRight, fullPathLeft);
|
||||
numActions++;
|
||||
break;
|
||||
case ActionFileCmp_DeleteRight:
|
||||
Print(" -* %s\n", showPath);
|
||||
AccionFileNodeAux_Delete(fullPathLeft, fullPathRight); numActions++;
|
||||
AccionFileNodeAux_Delete(fullPathLeft, fullPathRight);
|
||||
numActions++;
|
||||
break;
|
||||
case ActionFileCmp_DateLeftToRight:
|
||||
Print(" -> %s\n", showPath);
|
||||
AccionFileNodeAux_CopyDate(fullPathLeft, fullPathRight); numActions++;
|
||||
AccionFileNodeAux_CopyDate(fullPathLeft, fullPathRight);
|
||||
numActions++;
|
||||
break;
|
||||
case ActionFileCmp_DateRightToLeft:
|
||||
Print(" <- %s\n", showPath);
|
||||
AccionFileNodeAux_CopyDate(fullPathRight, fullPathLeft); numActions++;
|
||||
AccionFileNodeAux_CopyDate(fullPathRight, fullPathLeft);
|
||||
numActions++;
|
||||
break;
|
||||
case ActionFileCmp_MakeRightDirectory:
|
||||
Print(" -D %s\n", showPath);
|
||||
AccionFileNodeAux_MakeDir(fullPathLeft, fullPathRight); numActions++;
|
||||
AccionFileNodeAux_MakeDir(fullPathLeft, fullPathRight);
|
||||
numActions++;
|
||||
break;
|
||||
case ActionFileCmp_MakeLeftDirectory:
|
||||
Print(" D- %s\n", showPath);
|
||||
AccionFileNodeAux_MakeDir(fullPathRight, fullPathLeft); numActions++;
|
||||
AccionFileNodeAux_MakeDir(fullPathRight, fullPathLeft);
|
||||
numActions++;
|
||||
break;
|
||||
}
|
||||
|
||||
actionFileNode = actionFileNode->next;
|
||||
}
|
||||
Print("End\n");
|
||||
return numActions;
|
||||
return numActions;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// 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,
|
||||
ActionFileNode *actionFileNodeQueue)
|
||||
{
|
||||
ActionFileNode actionFileNodeNew = ActionFileNode_CreateNormal(
|
||||
fileNodeLeft, fileNodeRight);
|
||||
ActionFileNode *actionFileNodeQueue) {
|
||||
ActionFileNode actionFileNodeNew =
|
||||
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||
|
||||
if (!fileNodeLeft && !fileNodeRight) {
|
||||
AccionFileNode_Destroy(actionFileNodeNew);
|
||||
@@ -365,15 +358,14 @@ void AccionFileNode_DeletePair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
if (fileNodeRight->flags & FileFlag_Directory) {
|
||||
// Iterate childs for deletion
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew, actionFileNodeQueue,
|
||||
AccionFileNode_DeletePair);
|
||||
AccionFileNode_DeletePair);
|
||||
}
|
||||
|
||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||
// Node delete action
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
AccionFileNode_Destroy(actionFileNodeNew);
|
||||
}
|
||||
}
|
||||
@@ -381,26 +373,25 @@ void AccionFileNode_DeletePair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
if (fileNodeLeft->flags & FileFlag_Directory) {
|
||||
// Iterate childs for deletion
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew, actionFileNodeQueue,
|
||||
AccionFileNode_DeletePair);
|
||||
AccionFileNode_DeletePair);
|
||||
}
|
||||
|
||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||
// Node delete action
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
AccionFileNode_Destroy(actionFileNodeNew);
|
||||
}
|
||||
}
|
||||
if (fileNodeLeft && fileNodeRight) {
|
||||
if ((fileNodeLeft->flags & FileFlag_Directory)
|
||||
|| (fileNodeRight->flags & FileFlag_Directory)) {
|
||||
if ((fileNodeLeft->flags & FileFlag_Directory) ||
|
||||
(fileNodeRight->flags & FileFlag_Directory)) {
|
||||
// One is Directory
|
||||
|
||||
// Iterate childs for deletion
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew, actionFileNodeQueue,
|
||||
AccionFileNode_DeletePair);
|
||||
AccionFileNode_DeletePair);
|
||||
}
|
||||
|
||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||
@@ -411,8 +402,8 @@ void AccionFileNode_DeletePair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
}
|
||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||
if (!actionFileNodeNew) {
|
||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
||||
fileNodeRight);
|
||||
actionFileNodeNew =
|
||||
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||
}
|
||||
// Right node delete action
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
|
||||
@@ -26,13 +26,12 @@ struct TActionFileNode {
|
||||
ActionFileNode ActionFileNode_Create();
|
||||
void AccionFileNode_Destroy(ActionFileNode actionFileNode);
|
||||
ActionFileNode ActionFileNode_CreateNormal(FileNode fileNodeLeft,
|
||||
FileNode fileNodeRight);
|
||||
FileNode fileNodeRight);
|
||||
|
||||
void AccionFileNode_CompareChilds(
|
||||
ActionFileNode actionFileNodeRoot,
|
||||
ActionFileNode *actionFileNodeQueue,
|
||||
void(*CheckPair)(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
ActionFileNode *actionFileNodeQueue));
|
||||
ActionFileNode actionFileNodeRoot, ActionFileNode *actionFileNodeQueue,
|
||||
void (*CheckPair)(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
ActionFileNode *actionFileNodeQueue));
|
||||
|
||||
typedef struct SActionQueueStatistics {
|
||||
long long readLeft;
|
||||
@@ -48,16 +47,16 @@ typedef struct SActionQueueStatistics {
|
||||
} ActionQueueStatistics;
|
||||
|
||||
int ActionFileNode_Statistics(ActionFileNode actionFileNode,
|
||||
ActionQueueStatistics *statistics);
|
||||
ActionQueueStatistics *statistics);
|
||||
|
||||
void ActionFileNode_Print(ActionFileNode actionFileNode);
|
||||
|
||||
int ActionFileNode_RunList(ActionFileNode actionFileNode, char *pathLeft,
|
||||
char *pathRight);
|
||||
char *pathRight);
|
||||
|
||||
// Common utilities
|
||||
|
||||
void AccionFileNode_DeletePair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
ActionFileNode *actionFileNodeQueue);
|
||||
ActionFileNode *actionFileNodeQueue);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,13 +11,14 @@
|
||||
|
||||
#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,
|
||||
ActionFileNode *actionFileNodeQueue)
|
||||
{
|
||||
ActionFileNode actionFileNodeNew = ActionFileNode_CreateNormal(
|
||||
fileNodeLeft, fileNodeRight);
|
||||
ActionFileNode *actionFileNodeQueue) {
|
||||
ActionFileNode actionFileNodeNew =
|
||||
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||
|
||||
if (!fileNodeLeft && !fileNodeRight) {
|
||||
AccionFileNode_Destroy(actionFileNodeNew);
|
||||
@@ -26,13 +27,12 @@ void AccionFileNode_CopyPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
if (!fileNodeLeft && fileNodeRight) {
|
||||
if (fileNodeRight->flags & FileFlag_Directory) {
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew, actionFileNodeQueue,
|
||||
AccionFileNode_DeletePair);
|
||||
AccionFileNode_DeletePair);
|
||||
}
|
||||
|
||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
@@ -41,58 +41,59 @@ void AccionFileNode_CopyPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||
if (fileNodeLeft->flags & FileFlag_Directory) {
|
||||
actionFileNodeNew->action = ActionFileCmp_MakeRightDirectory;
|
||||
(*actionFileNodeQueue)->next = actionFileNodeNew;
|
||||
(*actionFileNodeQueue) = actionFileNodeNew;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||
actionFileNodeQueue, AccionFileNode_CopyPair);
|
||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
||||
fileNodeRight);
|
||||
actionFileNodeQueue,
|
||||
AccionFileNode_CopyPair);
|
||||
actionFileNodeNew =
|
||||
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
if (fileNodeLeft && fileNodeRight) {
|
||||
if ((fileNodeLeft->flags & FileFlag_Directory)
|
||||
|| (fileNodeRight->flags & FileFlag_Directory))
|
||||
{
|
||||
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;
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action =
|
||||
ActionFileCmp_MakeRightDirectory;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
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;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||
actionFileNodeQueue, AccionFileNode_DeletePair);
|
||||
actionFileNodeQueue,
|
||||
AccionFileNode_DeletePair);
|
||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime))
|
||||
<= MaxDeltaTime)
|
||||
{
|
||||
if (abs((int)(fileNodeLeft->fileTime -
|
||||
fileNodeRight->fileTime)) <= MaxDeltaTime) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
}
|
||||
@@ -103,11 +104,11 @@ void AccionFileNode_CopyPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
}
|
||||
|
||||
ActionFileNode ActionFileNode_BuildCopy(FileNode fileNodeLeft,
|
||||
FileNode fileNodeRight) {
|
||||
ActionFileNode actionFileNodeRoot = ActionFileNode_CreateNormal(
|
||||
fileNodeLeft, fileNodeRight);
|
||||
FileNode fileNodeRight) {
|
||||
ActionFileNode actionFileNodeRoot =
|
||||
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||
ActionFileNode actionFileNodeQueue = actionFileNodeRoot;
|
||||
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
||||
AccionFileNode_CopyPair);
|
||||
AccionFileNode_CopyPair);
|
||||
return actionFileNodeRoot;
|
||||
}
|
||||
@@ -5,6 +5,6 @@
|
||||
#include "actionfilenode.h"
|
||||
|
||||
ActionFileNode ActionFileNode_BuildCopy(FileNode fileNodeLeft,
|
||||
FileNode fileNodeRight);
|
||||
FileNode fileNodeRight);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -11,46 +11,44 @@
|
||||
|
||||
#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,
|
||||
ActionFileNode *actionFileNodeQueue)
|
||||
{
|
||||
ActionFileNode actionFileNodeNew = ActionFileNode_CreateNormal(
|
||||
fileNodeLeft, fileNodeRight);
|
||||
|
||||
ActionFileNode *actionFileNodeQueue) {
|
||||
if (!fileNodeLeft && !fileNodeRight) {
|
||||
AccionFileNode_Destroy(actionFileNodeNew);
|
||||
return;
|
||||
}
|
||||
ActionFileNode actionFileNodeNew =
|
||||
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||
|
||||
if (!fileNodeLeft && fileNodeRight) {
|
||||
if (fileNodeRight->flags & FileFlag_Directory) {
|
||||
// Directory
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
actionFileNodeNew->action = ActionFileCmp_MakeLeftDirectory;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
|
||||
// Iterate childs
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||
actionFileNodeQueue, AccionFileNode_SyncPair);
|
||||
actionFileNodeQueue,
|
||||
AccionFileNode_SyncPair);
|
||||
|
||||
// Creatre new action for date copy
|
||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
||||
fileNodeRight);
|
||||
// Create new action for date copy
|
||||
actionFileNodeNew =
|
||||
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||
actionFileNodeNew->action = ActionFileCmp_DateRightToLeft;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// File
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
actionFileNodeNew->action = ActionFileCmp_RightToLeft;
|
||||
}
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
@@ -62,111 +60,115 @@ void AccionFileNode_SyncPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
actionFileNodeNew->action = ActionFileCmp_MakeRightDirectory;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
|
||||
// Iterate childs
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||
actionFileNodeQueue, AccionFileNode_SyncPair);
|
||||
actionFileNodeQueue,
|
||||
AccionFileNode_SyncPair);
|
||||
|
||||
// Create new action for date copy
|
||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
||||
fileNodeRight);
|
||||
actionFileNodeNew =
|
||||
ActionFileNode_CreateNormal(fileNodeLeft, fileNodeRight);
|
||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// File
|
||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||
}
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
}
|
||||
if (fileNodeLeft && fileNodeRight) {
|
||||
if ((fileNodeLeft->flags & FileFlag_Directory)
|
||||
&& (fileNodeRight->flags & FileFlag_Directory))
|
||||
{
|
||||
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) {
|
||||
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) {
|
||||
} else if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||
}
|
||||
else if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
} else if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DateRightToLeft;
|
||||
} 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);
|
||||
}
|
||||
actionFileNodeNew->action = ActionFileCmp_DateRightToLeft;
|
||||
}
|
||||
}
|
||||
else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||
} else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
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
|
||||
if (actionFileNodeNew->action == ActionFileCmp_DeleteRight
|
||||
|| actionFileNodeNew->action == ActionFileCmp_DeleteLeft
|
||||
|| (fileNodeLeft->status == FileStatus_Deleted
|
||||
&& fileNodeRight->status == FileStatus_Deleted)) {
|
||||
if (actionFileNodeNew->action == ActionFileCmp_DeleteRight ||
|
||||
actionFileNodeNew->action == ActionFileCmp_DeleteLeft) {
|
||||
// Iterate child nodes for deletion
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||
actionFileNodeQueue, AccionFileNode_DeletePair);
|
||||
}
|
||||
else {
|
||||
actionFileNodeQueue,
|
||||
AccionFileNode_DeletePair);
|
||||
} else {
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||
actionFileNodeQueue, AccionFileNode_SyncPair);
|
||||
actionFileNodeQueue,
|
||||
AccionFileNode_SyncPair);
|
||||
}
|
||||
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
else if ((fileNodeLeft->flags & FileFlag_Normal)
|
||||
&& (fileNodeRight->flags & FileFlag_Normal))
|
||||
{
|
||||
} 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) {
|
||||
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) {
|
||||
} else if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||
}
|
||||
else if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
} else if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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
|
||||
actionFileNodeNew->action = ActionFileCmp_RightToLeft;
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
@@ -175,8 +177,7 @@ void AccionFileNode_SyncPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
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
|
||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
@@ -187,8 +188,7 @@ void AccionFileNode_SyncPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
}
|
||||
}
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// FIXME: !!!!!
|
||||
// Directory vs File
|
||||
}
|
||||
@@ -196,10 +196,10 @@ void AccionFileNode_SyncPair(FileNode fileNodeLeft, FileNode fileNodeRight,
|
||||
}
|
||||
|
||||
ActionFileNode ActionFileNode_BuildSync(FileNode izquierda, FileNode derecha) {
|
||||
ActionFileNode actionFileNodeRoot = ActionFileNode_CreateNormal(izquierda,
|
||||
derecha);
|
||||
ActionFileNode actionFileNodeRoot =
|
||||
ActionFileNode_CreateNormal(izquierda, derecha);
|
||||
ActionFileNode actionFileNodeQueue = actionFileNodeRoot;
|
||||
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
||||
AccionFileNode_SyncPair);
|
||||
AccionFileNode_SyncPair);
|
||||
return actionFileNodeRoot;
|
||||
}
|
||||
@@ -5,6 +5,6 @@
|
||||
#include "actionfilenode.h"
|
||||
|
||||
ActionFileNode ActionFileNode_BuildSync(FileNode fileNodeLeft,
|
||||
FileNode fileNodeRight);
|
||||
FileNode fileNodeRight);
|
||||
|
||||
#endif
|
||||
|
||||
10
src/crc.c
10
src/crc.c
@@ -3,7 +3,7 @@
|
||||
unsigned long _crcTable[256];
|
||||
int _crcTableInitialized = 0;
|
||||
|
||||
#define CRC32_POLYNOMIAL 0xEDB88320L
|
||||
#define CRC32_POLYNOMIAL 0xEDB88320L
|
||||
|
||||
void CRCTable_Init() {
|
||||
int i;
|
||||
@@ -28,12 +28,11 @@ void CRCTable_Init() {
|
||||
}
|
||||
|
||||
unsigned long CRC_BufferInternal(unsigned char *buffer, unsigned long len,
|
||||
unsigned long crc)
|
||||
{
|
||||
unsigned long crc) {
|
||||
unsigned char *p;
|
||||
|
||||
// Calculate CRC from buffer
|
||||
p = (unsigned char*)buffer;
|
||||
p = (unsigned char *)buffer;
|
||||
while (len-- != 0) {
|
||||
unsigned long termA = (crc >> 8) & 0x00FFFFFFL;
|
||||
unsigned long termB = _crcTable[((int)crc ^ *p++) & 0xff];
|
||||
@@ -43,7 +42,8 @@ unsigned long CRC_BufferInternal(unsigned char *buffer, unsigned long len,
|
||||
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();
|
||||
return (CRC_BufferInternal(buffer, len, crc));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
#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);
|
||||
|
||||
#endif
|
||||
|
||||
202
src/filenode.c
202
src/filenode.c
@@ -95,10 +95,20 @@ void FileNode_AddChild(FileNode fileNode, FileNode fileNodeChild) {
|
||||
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) {
|
||||
FileNode fileNodeChild;
|
||||
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->status = status;
|
||||
@@ -113,8 +123,7 @@ void FileNode_GetPath_Rec(FileNode fileNode, char **pathNode) {
|
||||
if (fileNode->parent) {
|
||||
pathNode[0] = fileNode->parent->name;
|
||||
FileNode_GetPath_Rec(fileNode->parent, pathNode + 1);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
pathNode[0] = NULL;
|
||||
}
|
||||
}
|
||||
@@ -123,7 +132,9 @@ char *FileNode_GetPath(FileNode fileNode, char *path) {
|
||||
char *pathNodes[MaxPathNodes];
|
||||
int levels, i;
|
||||
char *pathPtr = tempPath;
|
||||
if (path) { pathPtr = path; }
|
||||
if (path) {
|
||||
pathPtr = path;
|
||||
}
|
||||
|
||||
FileNode_GetPath_Rec(fileNode, pathNodes);
|
||||
levels = 0;
|
||||
@@ -195,8 +206,7 @@ void FileNode_SaveNode(FileNode fileNode, FILE *file) {
|
||||
fwrite((void *)&nameLen, sizeof(nameLen), 1, file);
|
||||
if (nameLen > 0 && nameLen < MaxFilename) {
|
||||
fputs(fileNode->name, file);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -213,7 +223,8 @@ void FileNode_SaveNode(FileNode fileNode, FILE *file) {
|
||||
|
||||
// Write date
|
||||
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
|
||||
@@ -224,7 +235,8 @@ void FileNode_SaveNode(FileNode fileNode, FILE *file) {
|
||||
// Write files of directory
|
||||
if (fileNode->flags & FileFlag_Directory) {
|
||||
FileNode fileNodeChild;
|
||||
fwrite((void *)&fileNode->childCount, sizeof(fileNode->childCount), 1, file);
|
||||
fwrite((void *)&fileNode->childCount, sizeof(fileNode->childCount), 1,
|
||||
file);
|
||||
fileNodeChild = fileNode->child;
|
||||
int cnt = 0;
|
||||
while (fileNodeChild) {
|
||||
@@ -269,7 +281,7 @@ FileNode FileNode_LoadNode(FILE *file) {
|
||||
// Read name
|
||||
fread((void *)&nameLen, sizeof(nameLen), 1, file);
|
||||
fileNode->name[0] = 0;
|
||||
if (nameLen<0 || nameLen>MaxFilename) {
|
||||
if (nameLen < 0 || nameLen > MaxFilename) {
|
||||
FileNode_Delete(fileNode);
|
||||
return NULL;
|
||||
}
|
||||
@@ -306,7 +318,8 @@ FileNode FileNode_LoadNode(FILE *file) {
|
||||
if (fileNode->flags & FileFlag_Directory) {
|
||||
FileNode fileNodeChildAux = NULL;
|
||||
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++) {
|
||||
fileNodeChild = FileNode_LoadNode(file);
|
||||
if (fileNodeChild == NULL) {
|
||||
@@ -316,8 +329,7 @@ FileNode FileNode_LoadNode(FILE *file) {
|
||||
fileNodeChild->parent = fileNode;
|
||||
if (!fileNodeChildAux) {
|
||||
fileNode->child = fileNodeChild;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fileNodeChildAux->next = fileNodeChild;
|
||||
}
|
||||
fileNodeChildAux = fileNodeChild;
|
||||
@@ -362,8 +374,7 @@ void FileNode_PrintNode(FileNode fileNode) {
|
||||
Print(FileNode_GetPath(fileNode, NULL));
|
||||
if (fileNode->flags & FileFlag_Normal) {
|
||||
Print(" File");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Print(" Dir");
|
||||
}
|
||||
Print(" %d", fileNode->status);
|
||||
@@ -378,13 +389,15 @@ void FileNode_PrintNode(FileNode fileNode) {
|
||||
}
|
||||
Print("\n");
|
||||
|
||||
if (fileNode->flags&FileFlag_HasSize) {
|
||||
if (fileNode->flags & FileFlag_HasSize) {
|
||||
Print("\\-Size : %lld\n", fileNode->size);
|
||||
}
|
||||
if (fileNode->flags&FileFlag_HasTime) {
|
||||
Print("\\-Date : "); FileTime_Print(fileNode->fileTime); Print("\n");
|
||||
if (fileNode->flags & FileFlag_HasTime) {
|
||||
Print("\\-Date : ");
|
||||
FileTime_Print(fileNode->fileTime);
|
||||
Print("\n");
|
||||
}
|
||||
if (fileNode->flags&FileFlag_HasCRC) {
|
||||
if (fileNode->flags & FileFlag_HasCRC) {
|
||||
Print("\\-CRC : [%08X]\n", fileNode->crc);
|
||||
}
|
||||
}
|
||||
@@ -400,8 +413,7 @@ void FileNode_Print(FileNode fileNode) {
|
||||
|
||||
if (fileNodeAux->child) {
|
||||
fileNodeAux = fileNodeAux->child;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
while (fileNodeAux->next == NULL) {
|
||||
fileNodeAux = fileNodeAux->parent;
|
||||
if (fileNodeAux == fileNode || fileNodeAux == NULL) {
|
||||
@@ -428,14 +440,15 @@ FileNode FileNode_Build(char *path) {
|
||||
// Create node
|
||||
fileNode = FileNode_Create();
|
||||
File_GetName(path, fileNode->name);
|
||||
fileNode->fileTime = Time_GetCurrentTime();
|
||||
fileNode->flags |= FileFlag_HasTime;
|
||||
|
||||
if (File_IsDirectory(path)) {
|
||||
// Get information data from directories, and child files
|
||||
fileNode->flags |= FileFlag_Directory;
|
||||
FileNode_LoadTime(fileNode, path);
|
||||
File_IterateDir(path, FileNode_Build_Iterate, fileNode);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Get information data from files
|
||||
fileNode->flags |= FileFlag_Normal;
|
||||
FileNode_LoadSizeAndTime(fileNode, path);
|
||||
@@ -461,90 +474,91 @@ int FileNode_Build_Iterate(char *path, char *name, void *d) {
|
||||
int FileNode_Refresh_Iterate(char *path, char *name, void *d);
|
||||
|
||||
FileNode FileNode_Refresh(FileNode fileNode, char *filePath) {
|
||||
if (!fileNode) {
|
||||
Print("FileNode_Refresh: Error NULL FileNode\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!File_ExistsPath(filePath)) {
|
||||
// The file/directory has been deleted
|
||||
if (!fileNode) {
|
||||
fileNode = FileNode_Create();
|
||||
File_GetName(filePath, fileNode->name);
|
||||
}
|
||||
FileNode_SetStatusRec(fileNode, FileStatus_Deleted);
|
||||
return (fileNode);
|
||||
}
|
||||
if (!fileNode) {
|
||||
// The file has been created
|
||||
fileNode = FileNode_Build(filePath);
|
||||
FileNode_SetStatusRec(fileNode, FileStatus_New);
|
||||
}
|
||||
else {
|
||||
// Check modification
|
||||
FileTime fileTime;
|
||||
long long size;
|
||||
|
||||
// Mark
|
||||
fileNode->flags &= ~FileFlag_MarkerForReview;
|
||||
// Check modification
|
||||
FileTime fileTime;
|
||||
long long size;
|
||||
|
||||
if (File_IsDirectory(filePath)) {
|
||||
FileNode fileNodeChild;
|
||||
// Remove mark
|
||||
fileNode->flags &= ~FileFlag_MarkerForReview;
|
||||
|
||||
// Check directory data
|
||||
if (!(fileNode->flags & FileFlag_Directory)) {
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->flags |= FileFlag_Directory;
|
||||
fileNode->flags &= ~FileFlag_Normal;
|
||||
}
|
||||
fileTime = FileTime_Get(filePath);
|
||||
if (fileTime != fileNode->fileTime) {
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->fileTime = fileTime;
|
||||
if (fileNode->fileTime < 0) {
|
||||
fileNode->fileTime = Time_GetCurrentTime();
|
||||
}
|
||||
}
|
||||
if (File_IsDirectory(filePath)) {
|
||||
FileNode fileNodeChild;
|
||||
|
||||
// Mark childs for review
|
||||
fileNodeChild = fileNode->child;
|
||||
while (fileNodeChild) {
|
||||
fileNodeChild->flags |= FileFlag_MarkerForReview;
|
||||
fileNodeChild = fileNodeChild->next;
|
||||
}
|
||||
|
||||
// Scan subdirectories
|
||||
File_IterateDir(filePath, FileNode_Refresh_Iterate, fileNode);
|
||||
|
||||
// Mark as deleted remaining files marked for review
|
||||
fileNodeChild = fileNode->child;
|
||||
while (fileNodeChild) {
|
||||
if (fileNodeChild->flags & FileFlag_MarkerForReview) {
|
||||
fileNodeChild->flags &= ~FileFlag_MarkerForReview;
|
||||
FileNode_SetStatusRec(fileNodeChild, FileStatus_Deleted);
|
||||
}
|
||||
fileNodeChild = fileNodeChild->next;
|
||||
// Check directory data
|
||||
if (!(fileNode->flags & FileFlag_Directory)) {
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->flags |= FileFlag_Directory;
|
||||
fileNode->flags &= ~FileFlag_Normal;
|
||||
}
|
||||
fileTime = FileTime_Get(filePath);
|
||||
if (fileTime != fileNode->fileTime) {
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->fileTime = fileTime;
|
||||
if (fileNode->fileTime < 0) {
|
||||
fileNode->fileTime = Time_GetCurrentTime();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Comprar datos de los ficheros
|
||||
if (!(fileNode->flags & FileFlag_Normal)) {
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->flags |= FileFlag_Normal;
|
||||
fileNode->flags &= ~FileFlag_Directory;
|
||||
|
||||
// Mark childs for review
|
||||
fileNodeChild = fileNode->child;
|
||||
while (fileNodeChild) {
|
||||
fileNodeChild->flags |= FileFlag_MarkerForReview;
|
||||
fileNodeChild = fileNodeChild->next;
|
||||
}
|
||||
|
||||
// Scan subdirectories
|
||||
File_IterateDir(filePath, FileNode_Refresh_Iterate, fileNode);
|
||||
|
||||
// Mark as deleted remaining files marked for review
|
||||
fileNodeChild = fileNode->child;
|
||||
while (fileNodeChild) {
|
||||
if (fileNodeChild->flags & FileFlag_MarkerForReview) {
|
||||
fileNodeChild->flags &= ~FileFlag_MarkerForReview;
|
||||
FileNode_SetStatusRec(fileNodeChild, FileStatus_Deleted);
|
||||
}
|
||||
File_GetSizeAndTime(filePath, &size, &fileTime);
|
||||
if (size != fileNode->size) {
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->size = size;
|
||||
}
|
||||
if (fileTime != fileNode->fileTime) {
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->fileTime = fileTime;
|
||||
if (fileNode->fileTime < 0) {
|
||||
fileNode->fileTime = Time_GetCurrentTime();
|
||||
}
|
||||
}
|
||||
if (fileNode->status == FileStatus_Modified) {
|
||||
fileNode->flags &= ~FileFlag_HasCRC;
|
||||
fileNodeChild = fileNodeChild->next;
|
||||
}
|
||||
} else {
|
||||
// Comprar datos de los ficheros
|
||||
if (!(fileNode->flags & FileFlag_Normal)) {
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->flags |= FileFlag_Normal;
|
||||
fileNode->flags &= ~FileFlag_Directory;
|
||||
}
|
||||
File_GetSizeAndTime(filePath, &size, &fileTime);
|
||||
if (size != fileNode->size) {
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->size = size;
|
||||
}
|
||||
if (fileTime != fileNode->fileTime) {
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->fileTime = fileTime;
|
||||
if (fileNode->fileTime < 0) {
|
||||
fileNode->fileTime = Time_GetCurrentTime();
|
||||
}
|
||||
}
|
||||
if (fileNode->status == FileStatus_Modified) {
|
||||
fileNode->flags &= ~FileFlag_HasCRC;
|
||||
}
|
||||
}
|
||||
|
||||
// Save update time on root FileNode
|
||||
if (fileNode->parent == NULL) {
|
||||
fileNode->fileTime = Time_GetCurrentTime();
|
||||
fileNode->flags |= FileFlag_HasTime;
|
||||
}
|
||||
|
||||
return (fileNode);
|
||||
}
|
||||
|
||||
@@ -567,10 +581,10 @@ int FileNode_Refresh_Iterate(char *path, char *name, void *d) {
|
||||
if (fileNodeChild) {
|
||||
// Exists, Refresh
|
||||
FileNode_Refresh(fileNodeChild, path);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// New, Build
|
||||
fileNodeChild = FileNode_Refresh(NULL, path);
|
||||
fileNodeChild = FileNode_Build(path);
|
||||
FileNode_SetStatusRec(fileNodeChild, FileStatus_New);
|
||||
FileNode_AddChild(fileNode, fileNodeChild);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ FileNode FileNode_Create();
|
||||
FileNode FileNode_Copy(FileNode fileNode);
|
||||
void FileNode_Delete(FileNode fileNode);
|
||||
void FileNode_AddChild(FileNode file, FileNode file2);
|
||||
FileNode FileNode_GetRoot(FileNode fileNode);
|
||||
|
||||
char *FileNode_GetFullPath(FileNode fileNode, char *basePath, char *path);
|
||||
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
|
||||
#ifdef WIN32
|
||||
# define _WIN32_WINNT 0x0501
|
||||
# include <direct.h>
|
||||
# include <windows.h>
|
||||
# include <io.h>
|
||||
# include <stdio.h>
|
||||
# include <signal.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <time.h>
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#include <direct.h>
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#else
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/stat.h>
|
||||
# include <time.h>
|
||||
# include <utime.h>
|
||||
# include <dirent.h>
|
||||
# include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "util.h"
|
||||
@@ -69,7 +69,7 @@ FileTime FileTime_Get(char *fileName) {
|
||||
HANDLE hFile;
|
||||
FILETIME ftCreate, ftAccess, ftWrite;
|
||||
hFile = CreateFile(fileName, READ_CONTROL, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite);
|
||||
CloseHandle(hFile);
|
||||
return (FileTime_to_POSIX(ftWrite));
|
||||
@@ -83,7 +83,7 @@ void FileTime_Set(char *fileName, FileTime fileTime) {
|
||||
HANDLE hFile;
|
||||
FILETIME ftWrite;
|
||||
hFile = CreateFile(fileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
ftWrite = POSIX_to_FileTime(fileTime);
|
||||
SetFileTime(hFile, NULL, NULL, &ftWrite);
|
||||
CloseHandle(hFile);
|
||||
@@ -123,9 +123,8 @@ void FileTime_Print(FileTime fileTime) {
|
||||
struct tm *tms;
|
||||
|
||||
tms = localtime((time_t *)&fileTime);
|
||||
Print("%04d-%02d-%02d %02d:%02d:%02d", tms->tm_year + 1900,
|
||||
tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min,
|
||||
tms->tm_sec);
|
||||
Print("%04d-%02d-%02d %02d:%02d:%02d", tms->tm_year + 1900, tms->tm_mon + 1,
|
||||
tms->tm_mday, tms->tm_hour, tms->tm_min, tms->tm_sec);
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -134,7 +133,7 @@ long long File_GetSize(char *fileName) {
|
||||
HANDLE hFile;
|
||||
DWORD fSize;
|
||||
hFile = CreateFile(fileName, READ_CONTROL, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
fSize = GetFileSize(hFile, NULL);
|
||||
CloseHandle(hFile);
|
||||
return (fSize);
|
||||
@@ -154,7 +153,7 @@ void File_GetSizeAndTime(char *fileName, long long *size, FileTime *time) {
|
||||
DWORD fSize;
|
||||
FILETIME ftCreate, ftAccess, ftWrite;
|
||||
hFile = CreateFile(fileName, READ_CONTROL, FILE_SHARE_READ, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
fSize = GetFileSize(hFile, NULL);
|
||||
GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite);
|
||||
CloseHandle(hFile);
|
||||
@@ -178,8 +177,7 @@ void File_GetName(char *path, char *name) {
|
||||
if (path[i] == '/' || path[i] == '\\') {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
@@ -265,19 +263,16 @@ int File_IsFile(char *fileName) {
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
int File_MakeDirectory(char *path) {
|
||||
return (CreateDirectory(path, NULL));
|
||||
}
|
||||
int File_MakeDirectory(char *path) { return (CreateDirectory(path, NULL)); }
|
||||
#else
|
||||
int File_MakeDirectory(char *path) {
|
||||
return (mkdir(path, 0777));
|
||||
}
|
||||
int File_MakeDirectory(char *path) { return (mkdir(path, 0777)); }
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
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;
|
||||
struct _finddata_t fileinfo;
|
||||
char f_path[MaxPath];
|
||||
@@ -305,7 +300,8 @@ void File_IterateDir(char *path,
|
||||
#else
|
||||
|
||||
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;
|
||||
struct dirent *entidad_dir;
|
||||
char f_path[MaxPath];
|
||||
@@ -320,9 +316,8 @@ void File_IterateDir(char *path,
|
||||
do {
|
||||
entidad_dir = readdir(directorio);
|
||||
if (entidad_dir != NULL) {
|
||||
if (strcmp(entidad_dir->d_name, ".")
|
||||
&& strcmp(entidad_dir->d_name, ".."))
|
||||
{
|
||||
if (strcmp(entidad_dir->d_name, ".") &&
|
||||
strcmp(entidad_dir->d_name, "..")) {
|
||||
// Each item
|
||||
snprintf(f_path, MaxPath, "%s/%s", path, entidad_dir->d_name);
|
||||
fin = func(f_path, entidad_dir->d_name, data);
|
||||
@@ -365,7 +360,7 @@ int File_Copy(const char *pathOrig, const char *pathDest) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
buffer = malloc(sizeof(char)*MaxBuffer);
|
||||
buffer = malloc(sizeof(char) * MaxBuffer);
|
||||
if (buffer == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -387,8 +382,14 @@ int File_Copy(const char *pathOrig, const char *pathDest) {
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (fOrig != NULL) { fclose(fOrig); }
|
||||
if (fDest != NULL) { fclose(fDest); }
|
||||
if (buffer != NULL) { free(buffer); }
|
||||
if (fOrig != NULL) {
|
||||
fclose(fOrig);
|
||||
}
|
||||
if (fDest != NULL) {
|
||||
fclose(fDest);
|
||||
}
|
||||
if (buffer != NULL) {
|
||||
free(buffer);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
@@ -45,7 +45,8 @@ int File_IsFile(char *path);
|
||||
int File_MakeDirectory(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_DeleteDirectory(char *path);
|
||||
|
||||
89
src/main.c
89
src/main.c
@@ -42,7 +42,8 @@ int main(int argc, char *argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Print("\n================================ FileSync ===================================\n");
|
||||
Print("\n================================ FileSync "
|
||||
"===================================\n");
|
||||
if (!strcmp(argv[1], "info") && argc >= 3) {
|
||||
// Informacion de ficheros
|
||||
int i;
|
||||
@@ -53,18 +54,18 @@ int main(int argc, char *argv[]) {
|
||||
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
|
||||
long long tScan = Time_GetTime();
|
||||
FileNode fileNode;
|
||||
Print("Building FileNode..\n");
|
||||
fileNode = FileNode_Build(argv[2]);
|
||||
tScan = Time_GetTime() - tScan;
|
||||
Print("\ttScan :"); PrintElapsedTime(tScan); Print("\n");
|
||||
Print("\ttScan :");
|
||||
PrintElapsedTime(tScan);
|
||||
Print("\n");
|
||||
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
|
||||
FileNode fileNode;
|
||||
Print("Loading FileNode..\n");
|
||||
@@ -74,26 +75,27 @@ int main(int argc, char *argv[]) {
|
||||
long long tScan = Time_GetTime();
|
||||
fileNode = FileNode_Refresh(fileNode, argv[2]);
|
||||
tScan = Time_GetTime() - tScan;
|
||||
Print("\ttScan :"); PrintElapsedTime(tScan); Print("\n");
|
||||
Print("\ttScan :");
|
||||
PrintElapsedTime(tScan);
|
||||
Print("\n");
|
||||
FileNode_Save(fileNode, argv[3]);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Print("Building FileNode..\n");
|
||||
long long tScan = Time_GetTime();
|
||||
fileNode = FileNode_Build(argv[2]);
|
||||
tScan = Time_GetTime() - tScan;
|
||||
Print("\ttScan :"); PrintElapsedTime(tScan); Print("\n");
|
||||
Print("\ttScan :");
|
||||
PrintElapsedTime(tScan);
|
||||
Print("\n");
|
||||
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
|
||||
FileNode fileNode;
|
||||
fileNode = FileNode_Load(argv[2]);
|
||||
if (fileNode)
|
||||
FileNode_Print(fileNode);
|
||||
}
|
||||
else if (!strcmp(argv[1], "dir") && argc == 3) {
|
||||
} else if (!strcmp(argv[1], "dir") && argc == 3) {
|
||||
// Read directory information tree
|
||||
char *path = argv[2];
|
||||
FileNode fileNode;
|
||||
@@ -102,44 +104,34 @@ int main(int argc, char *argv[]) {
|
||||
if (fileNode) {
|
||||
FileNode_Print(fileNode);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argv[1], "check") && argc == 3) {
|
||||
} else if (!strcmp(argv[1], "check") && argc == 3) {
|
||||
// Read directory information tree
|
||||
char *path = argv[2];
|
||||
FileNode fileNode;
|
||||
|
||||
fileNode = CheckDir(path, 1);
|
||||
}
|
||||
else if (argc == 4) {
|
||||
} else if (argc == 4) {
|
||||
char *cmd = argv[1];
|
||||
char *pathLeft = argv[2];
|
||||
char *pathRight = argv[3];
|
||||
if (!strcmp(cmd, "sync")) {
|
||||
Sync(pathLeft, pathRight, 1, 0);
|
||||
}
|
||||
else if (!strcmp(cmd, "resync")) {
|
||||
} else if (!strcmp(cmd, "resync")) {
|
||||
Sync(pathLeft, pathRight, 0, 0);
|
||||
}
|
||||
else if (!strcmp(cmd, "synctest")) {
|
||||
} else if (!strcmp(cmd, "synctest")) {
|
||||
Sync(pathLeft, pathRight, 1, 1);
|
||||
}
|
||||
else if (!strcmp(cmd, "resynctest")) {
|
||||
} else if (!strcmp(cmd, "resynctest")) {
|
||||
Sync(pathLeft, pathRight, 0, 1);
|
||||
}
|
||||
else if (!strcmp(cmd, "copy")) {
|
||||
} else if (!strcmp(cmd, "copy")) {
|
||||
Copy(pathLeft, pathRight, 1, 0);
|
||||
}
|
||||
else if (!strcmp(cmd, "recopy")) {
|
||||
} else if (!strcmp(cmd, "recopy")) {
|
||||
Copy(pathLeft, pathRight, 0, 0);
|
||||
}
|
||||
else if (!strcmp(cmd, "copytest")) {
|
||||
} else if (!strcmp(cmd, "copytest")) {
|
||||
Copy(pathLeft, pathRight, 1, 1);
|
||||
}
|
||||
else if (!strcmp(cmd, "recopytest")) {
|
||||
} else if (!strcmp(cmd, "recopytest")) {
|
||||
Copy(pathLeft, pathRight, 0, 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Help(argv[0]);
|
||||
}
|
||||
|
||||
@@ -151,22 +143,22 @@ FileNode CheckDir(char *path, int recheck) {
|
||||
FileNode fileNode;
|
||||
|
||||
// Check directory
|
||||
snprintf(dirNodesFile, MaxPath, "%s/"FileNode_Filename, path);
|
||||
snprintf(dirNodesFile, MaxPath, "%s/" FileNode_Filename, path);
|
||||
if (recheck) {
|
||||
Print("Checking Directory.. %s\n", path);
|
||||
long long tScan = Time_GetTime();
|
||||
fileNode = FileNode_Load(dirNodesFile);
|
||||
if (fileNode) {
|
||||
fileNode = FileNode_Refresh(fileNode, path);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fileNode = FileNode_Build(path);
|
||||
}
|
||||
tScan = Time_GetTime() - tScan;
|
||||
Print("\ttScan :"); PrintElapsedTime(tScan); Print("\n");
|
||||
Print("\ttScan :");
|
||||
PrintElapsedTime(tScan);
|
||||
Print("\n");
|
||||
FileNode_Save(fileNode, dirNodesFile);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Print("Loading Directory.. %s\n", path);
|
||||
fileNode = FileNode_Load(dirNodesFile);
|
||||
if (!fileNode) {
|
||||
@@ -185,8 +177,7 @@ void PrintStatistics(ActionFileNode actionFileNode) {
|
||||
}
|
||||
Print("Statistics\n");
|
||||
|
||||
Print(" % 8s % 8s % 8s\n",
|
||||
"Read", "Write", "Delete");
|
||||
Print(" % 8s % 8s % 8s\n", "Read", "Write", "Delete");
|
||||
Print("Left :");
|
||||
PrintDataSize(statistics.readLeft);
|
||||
PrintDataSize(statistics.writeLeft);
|
||||
@@ -233,14 +224,15 @@ int Sync(char *pathLeft, char *pathRight, int reCheck, int dryRun) {
|
||||
ActionFileNode actionFileNode = NULL;
|
||||
actionFileNode = ActionFileNode_BuildSync(fileNodeLeft, fileNodeRight);
|
||||
tBuild = Time_GetTime() - tBuild;
|
||||
Print("\ttBuild:"); PrintElapsedTime(tBuild); Print("\n");
|
||||
Print("\ttBuild:");
|
||||
PrintElapsedTime(tBuild);
|
||||
Print("\n");
|
||||
|
||||
if (dryRun) {
|
||||
// Show action list
|
||||
ActionFileNode_Print(actionFileNode);
|
||||
PrintStatistics(actionFileNode);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Run action list
|
||||
if (ActionFileNode_RunList(actionFileNode, pathLeft, pathRight)) {
|
||||
CheckDir(pathLeft, reCheck);
|
||||
@@ -279,14 +271,15 @@ int Copy(char *pathLeft, char *pathRight, int reCheck, int dryRun) {
|
||||
ActionFileNode actionFileNode = NULL;
|
||||
actionFileNode = ActionFileNode_BuildCopy(fileNodeLeft, fileNodeRight);
|
||||
tBuild = Time_GetTime() - tBuild;
|
||||
Print("\ttBuild:"); PrintElapsedTime(tBuild); Print("\n");
|
||||
Print("\ttBuild:");
|
||||
PrintElapsedTime(tBuild);
|
||||
Print("\n");
|
||||
|
||||
if (dryRun) {
|
||||
// Show action list
|
||||
ActionFileNode_Print(actionFileNode);
|
||||
PrintStatistics(actionFileNode);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Run action list
|
||||
if (ActionFileNode_RunList(actionFileNode, pathLeft, pathRight)) {
|
||||
CheckDir(pathLeft, reCheck);
|
||||
|
||||
@@ -35,7 +35,7 @@ long long Time_GetTime() {
|
||||
QueryPerformanceFrequency(&freq);
|
||||
QueryPerformanceCounter(&tim);
|
||||
microt = (tim.QuadPart * 1000000) / freq.QuadPart;
|
||||
return(microt);
|
||||
return (microt);
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
@@ -51,8 +51,7 @@ void Time_Pause(int pausa) {
|
||||
diff = tend - t;
|
||||
if (diff > 1000) {
|
||||
Sleep((int)diff / 1000);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Sleep(0);
|
||||
}
|
||||
t = Time_GetTime();
|
||||
@@ -68,7 +67,7 @@ long long Time_GetTime() {
|
||||
long long usecs;
|
||||
gettimeofday(&t, NULL);
|
||||
usecs = (t.tv_sec * 1000000ll) + (t.tv_usec);
|
||||
return(usecs);
|
||||
return (usecs);
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
@@ -154,5 +153,5 @@ int Print(char *fmt, ...) {
|
||||
|
||||
// Flush
|
||||
fflush(stdout);
|
||||
return(n);
|
||||
return (n);
|
||||
}
|
||||
Reference in New Issue
Block a user