Print statistict on every action.

This commit is contained in:
2018-05-05 14:08:44 +02:00
parent 7e9d5063af
commit d201c58ba3
3 changed files with 80 additions and 23 deletions

View File

@@ -2,11 +2,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "util.h"
#include "crc.h"
#include "fileutil.h"
#include "filenode.h"
#include "actionfilenode.h" #include "actionfilenode.h"
#include "crc.h"
#include "filenode.h"
#include "fileutil.h"
#include "util.h"
ActionFileNode _actionFileNodeFree = NULL; ActionFileNode _actionFileNodeFree = NULL;
#define AccionFileNode_Block 1024 #define AccionFileNode_Block 1024
@@ -37,6 +37,7 @@ ActionFileNode ActionFileNode_Create() {
actionFileNode->action = ActionFileCmp_Nothing; actionFileNode->action = ActionFileCmp_Nothing;
actionFileNode->left = NULL; actionFileNode->left = NULL;
actionFileNode->right = NULL; actionFileNode->right = NULL;
actionFileNode->result = ActionFileNodeResult_Nothing;
actionFileNode->next = NULL; actionFileNode->next = NULL;
return (actionFileNode); return (actionFileNode);
@@ -141,7 +142,8 @@ void AccionFileNode_CompareChilds(
} }
int ActionFileNode_Statistics(ActionFileNode actionFileNode, int ActionFileNode_Statistics(ActionFileNode actionFileNode,
ActionQueueStatistics *statistics) { ActionQueueStatistics *statistics,
ActionFileNodeResult result) {
statistics->readLeft = 0; statistics->readLeft = 0;
statistics->writeLeft = 0; statistics->writeLeft = 0;
statistics->readRight = 0; statistics->readRight = 0;
@@ -155,6 +157,11 @@ int ActionFileNode_Statistics(ActionFileNode actionFileNode,
statistics->deleteCount = 0; statistics->deleteCount = 0;
while (actionFileNode != NULL) { while (actionFileNode != NULL) {
if (actionFileNode->result != result) {
actionFileNode = actionFileNode->next;
continue;
}
switch (actionFileNode->action) { switch (actionFileNode->action) {
case ActionFileCmp_Nothing: case ActionFileCmp_Nothing:
break; break;
@@ -240,33 +247,39 @@ void ActionFileNode_Print(ActionFileNode actionFileNode) {
Print("End\n"); Print("End\n");
} }
void AccionFileNodeAux_CopyDate(char *pathOrig, char *pathDest) { bool AccionFileNodeAux_CopyDate(char *pathOrig, char *pathDest) {
FileTime ft = FileTime_Get(pathOrig); FileTime ft = FileTime_Get(pathOrig);
FileTime_Set(pathDest, ft); FileTime_Set(pathDest, ft);
return true;
} }
void AccionFileNodeAux_Copy(char *pathOrig, char *pathDest) { bool AccionFileNodeAux_Copy(char *pathOrig, char *pathDest) {
if (File_Copy(pathOrig, pathDest)) { if (File_Copy(pathOrig, pathDest)) {
AccionFileNodeAux_CopyDate(pathOrig, pathDest); return AccionFileNodeAux_CopyDate(pathOrig, pathDest);
} else { } else {
File_Delete(pathDest); File_Delete(pathDest);
Print("Error Copying to: %s, %s\n", pathDest, GetError()); Print("Error Copying to: %s, %s\n", pathDest, GetError());
return false;
} }
} }
void AccionFileNodeAux_Delete(char *pathOrig, char *pathDest) { bool AccionFileNodeAux_Delete(char *pathOrig, char *pathDest) {
if (File_IsDirectory(pathDest)) { if (File_IsDirectory(pathDest)) {
if (File_DeleteDirectory(pathDest) == 0) { if (File_DeleteDirectory(pathDest) == 0) {
Print("Error Deleting Directory: %s, %s\n", pathDest, GetError()); Print("Error Deleting Directory: %s, %s\n", pathDest, GetError());
return false;
} }
} else { } else {
if (File_Delete(pathDest) == 0) { if (File_Delete(pathDest) == 0) {
Print("Error Deleting File: %s, %s\n", pathDest, GetError()); Print("Error Deleting File: %s, %s\n", pathDest, GetError());
return false;
} }
} }
return true;
} }
void AccionFileNodeAux_MakeDir(char *pathOrig, char *pathDest) { bool AccionFileNodeAux_MakeDir(char *pathOrig, char *pathDest) {
if (File_MakeDirectory(pathDest) == 0) { if (File_MakeDirectory(pathDest) == 0) {
Print("Error Making Directory: %s, %s\n", pathDest, GetError()); Print("Error Making Directory: %s, %s\n", pathDest, GetError());
return false;
} }
} }
@@ -296,42 +309,74 @@ int ActionFileNode_RunList(ActionFileNode actionFileNode, char *pathLeft,
break; break;
case ActionFileCmp_LeftToRight: case ActionFileCmp_LeftToRight:
Print(" => %s\n", showPath); Print(" => %s\n", showPath);
AccionFileNodeAux_Copy(fullPathLeft, fullPathRight); if (AccionFileNodeAux_Copy(fullPathLeft, fullPathRight)) {
actionFileNode->result = ActionFileNodeResult_Ok;
} else {
actionFileNode->result = ActionFileNodeResult_Error;
}
numActions++; numActions++;
break; break;
case ActionFileCmp_RightToLeft: case ActionFileCmp_RightToLeft:
Print(" <= %s\n", showPath); Print(" <= %s\n", showPath);
AccionFileNodeAux_Copy(fullPathRight, fullPathLeft); if (AccionFileNodeAux_Copy(fullPathRight, fullPathLeft)) {
actionFileNode->result = ActionFileNodeResult_Ok;
} else {
actionFileNode->result = ActionFileNodeResult_Error;
}
numActions++; numActions++;
break; break;
case ActionFileCmp_DeleteLeft: case ActionFileCmp_DeleteLeft:
Print(" *- %s\n", showPath); Print(" *- %s\n", showPath);
AccionFileNodeAux_Delete(fullPathRight, fullPathLeft); if (AccionFileNodeAux_Delete(fullPathRight, fullPathLeft)) {
actionFileNode->result = ActionFileNodeResult_Ok;
} else {
actionFileNode->result = ActionFileNodeResult_Error;
}
numActions++; numActions++;
break; break;
case ActionFileCmp_DeleteRight: case ActionFileCmp_DeleteRight:
Print(" -* %s\n", showPath); Print(" -* %s\n", showPath);
AccionFileNodeAux_Delete(fullPathLeft, fullPathRight); if (AccionFileNodeAux_Delete(fullPathLeft, fullPathRight)) {
actionFileNode->result = ActionFileNodeResult_Ok;
} else {
actionFileNode->result = ActionFileNodeResult_Error;
}
numActions++; numActions++;
break; break;
case ActionFileCmp_DateLeftToRight: case ActionFileCmp_DateLeftToRight:
Print(" -> %s\n", showPath); Print(" -> %s\n", showPath);
AccionFileNodeAux_CopyDate(fullPathLeft, fullPathRight); if (AccionFileNodeAux_CopyDate(fullPathLeft, fullPathRight)) {
actionFileNode->result = ActionFileNodeResult_Ok;
} else {
actionFileNode->result = ActionFileNodeResult_Error;
}
numActions++; numActions++;
break; break;
case ActionFileCmp_DateRightToLeft: case ActionFileCmp_DateRightToLeft:
Print(" <- %s\n", showPath); Print(" <- %s\n", showPath);
AccionFileNodeAux_CopyDate(fullPathRight, fullPathLeft); if (AccionFileNodeAux_CopyDate(fullPathRight, fullPathLeft)) {
actionFileNode->result = ActionFileNodeResult_Ok;
} else {
actionFileNode->result = ActionFileNodeResult_Error;
}
numActions++; numActions++;
break; break;
case ActionFileCmp_MakeRightDirectory: case ActionFileCmp_MakeRightDirectory:
Print(" -D %s\n", showPath); Print(" -D %s\n", showPath);
AccionFileNodeAux_MakeDir(fullPathLeft, fullPathRight); if (AccionFileNodeAux_MakeDir(fullPathLeft, fullPathRight)) {
actionFileNode->result = ActionFileNodeResult_Ok;
} else {
actionFileNode->result = ActionFileNodeResult_Error;
}
numActions++; numActions++;
break; break;
case ActionFileCmp_MakeLeftDirectory: case ActionFileCmp_MakeLeftDirectory:
Print(" D- %s\n", showPath); Print(" D- %s\n", showPath);
AccionFileNodeAux_MakeDir(fullPathRight, fullPathLeft); if (AccionFileNodeAux_MakeDir(fullPathRight, fullPathLeft)) {
actionFileNode->result = ActionFileNodeResult_Ok;
} else {
actionFileNode->result = ActionFileNodeResult_Error;
}
numActions++; numActions++;
break; break;
} }

View File

@@ -15,11 +15,20 @@ typedef enum EActionFileCmp {
ActionFileCmp_MakeLeftDirectory ActionFileCmp_MakeLeftDirectory
} ActionFileCmp; } ActionFileCmp;
typedef enum EActionFileNodeResult {
ActionFileNodeResult_Nothing,
ActionFileNodeResult_Ok,
ActionFileNodeResult_Error
} ActionFileNodeResult;
typedef struct SActionFileNode TActionFileNode, *ActionFileNode; typedef struct SActionFileNode TActionFileNode, *ActionFileNode;
struct SActionFileNode { struct SActionFileNode {
ActionFileCmp action; ActionFileCmp action;
FileNode left; FileNode left;
FileNode right; FileNode right;
ActionFileNodeResult result;
ActionFileNode next; ActionFileNode next;
}; };
@@ -47,7 +56,8 @@ typedef struct SActionQueueStatistics {
} ActionQueueStatistics; } ActionQueueStatistics;
int ActionFileNode_Statistics(ActionFileNode actionFileNode, int ActionFileNode_Statistics(ActionFileNode actionFileNode,
ActionQueueStatistics *statistics); ActionQueueStatistics *statistics,
ActionFileNodeResult result);
void ActionFileNode_Print(ActionFileNode actionFileNode); void ActionFileNode_Print(ActionFileNode actionFileNode);

View File

@@ -42,9 +42,9 @@ FileNode CheckDir(char *path, int recheck) {
return fileNode; return fileNode;
} }
void PrintStatistics(ActionFileNode actionFileNode) { void PrintStatistics(ActionFileNode actionFileNode, ActionFileNodeResult result) {
ActionQueueStatistics statistics; ActionQueueStatistics statistics;
if (ActionFileNode_Statistics(actionFileNode, &statistics) == 0) { if (ActionFileNode_Statistics(actionFileNode, &statistics, result) == 0) {
Print("Noting to do.\n"); Print("Noting to do.\n");
return; return;
} }
@@ -104,10 +104,11 @@ int Sync(char *pathLeft, char *pathRight, int reCheck, int dryRun) {
if (dryRun) { if (dryRun) {
// Show action list // Show action list
ActionFileNode_Print(actionFileNode); ActionFileNode_Print(actionFileNode);
PrintStatistics(actionFileNode); PrintStatistics(actionFileNode, ActionFileNodeResult_Nothing);
} else { } else {
// Run action list // Run action list
if (ActionFileNode_RunList(actionFileNode, pathLeft, pathRight)) { if (ActionFileNode_RunList(actionFileNode, pathLeft, pathRight)) {
PrintStatistics(actionFileNode, ActionFileNodeResult_Ok);
CheckDir(pathLeft, reCheck); CheckDir(pathLeft, reCheck);
CheckDir(pathRight, reCheck); CheckDir(pathRight, reCheck);
} }
@@ -151,10 +152,11 @@ int Copy(char *pathLeft, char *pathRight, int reCheck, int dryRun) {
if (dryRun) { if (dryRun) {
// Show action list // Show action list
ActionFileNode_Print(actionFileNode); ActionFileNode_Print(actionFileNode);
PrintStatistics(actionFileNode); PrintStatistics(actionFileNode, ActionFileNodeResult_Nothing);
} else { } else {
// Run action list // Run action list
if (ActionFileNode_RunList(actionFileNode, pathLeft, pathRight)) { if (ActionFileNode_RunList(actionFileNode, pathLeft, pathRight)) {
PrintStatistics(actionFileNode, ActionFileNodeResult_Ok);
CheckDir(pathLeft, reCheck); CheckDir(pathLeft, reCheck);
CheckDir(pathRight, reCheck); CheckDir(pathRight, reCheck);
} }