Miscellaneous fixes
This commit is contained in:
@@ -31,7 +31,7 @@ unsigned long CRC_BufferInternal(unsigned char *buffer, int len,
|
||||
unsigned long crc) {
|
||||
unsigned char *p;
|
||||
|
||||
// Calcular CRC del buffer
|
||||
// Calculate CRC from buffer
|
||||
p = (unsigned char*)buffer;
|
||||
while (len-- != 0) {
|
||||
unsigned long termA = (crc >> 8) & 0x00FFFFFFL;
|
||||
@@ -55,12 +55,11 @@ unsigned long CRC_File(FILE *file) {
|
||||
|
||||
crc = 0xFFFFFFFFL;
|
||||
for (;;) {
|
||||
// Llenar el buffer
|
||||
// Fill buffer
|
||||
int count = fread(buffer, 1, 512, file);
|
||||
if (count == 0)
|
||||
break;
|
||||
|
||||
// Calcular CRC del buffer
|
||||
crc = CRC_BufferInternal(buffer, count, crc);
|
||||
}
|
||||
return (crc ^= 0xFFFFFFFFL);
|
||||
|
||||
173
src/filenode.c
173
src/filenode.c
@@ -16,8 +16,11 @@ FileNode *FileNode_Create() {
|
||||
if (_free_filenode == NULL) {
|
||||
FileNode *nodos;
|
||||
int i;
|
||||
// Reservar un tocho
|
||||
// Allocate a block
|
||||
nodos = malloc(sizeof(FileNode) * FileNode_Block);
|
||||
if (nodos == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < FileNode_Block - 1; i++) {
|
||||
nodos[i].next = &nodos[i + 1];
|
||||
}
|
||||
@@ -25,15 +28,16 @@ FileNode *FileNode_Create() {
|
||||
_free_filenode = &nodos[0];
|
||||
}
|
||||
|
||||
// Obtener el primero libre
|
||||
// Get first free
|
||||
fileNode = _free_filenode;
|
||||
_free_filenode = fileNode->next;
|
||||
fileNode->next = NULL;
|
||||
_n_filenode++;
|
||||
|
||||
// Iniciar
|
||||
// Initialize
|
||||
fileNode->name[0] = 0;
|
||||
fileNode->flags = 0;
|
||||
fileNode->estado = FileStatus_None;
|
||||
fileNode->status = FileStatus_None;
|
||||
fileNode->size = 0;
|
||||
fileNode->crc = 0;
|
||||
fileNode->fileTime = 0;
|
||||
@@ -49,6 +53,7 @@ void FileNode_Delete(FileNode *fn) {
|
||||
fn->next = _free_filenode;
|
||||
_free_filenode = fn;
|
||||
_n_filenode--;
|
||||
// FIXME: delete childs
|
||||
}
|
||||
|
||||
void FileNode_AddChild(FileNode *fileNode, FileNode *file2) {
|
||||
@@ -60,12 +65,12 @@ void FileNode_AddChild(FileNode *fileNode, FileNode *file2) {
|
||||
file2->parent = fileNode;
|
||||
}
|
||||
|
||||
void FileNode_SetEstadoRec(FileNode *fileNode, FileStatus estado) {
|
||||
void FileNode_SetStatusRec(FileNode *fileNode, FileStatus status) {
|
||||
FileNode *fn_child;
|
||||
fileNode->estado = estado;
|
||||
fileNode->status = status;
|
||||
fn_child = fileNode->child;
|
||||
while (fn_child != NULL) {
|
||||
FileNode_SetEstadoRec(fn_child, estado);
|
||||
FileNode_SetStatusRec(fn_child, status);
|
||||
fn_child = fn_child->next;
|
||||
}
|
||||
}
|
||||
@@ -74,7 +79,8 @@ 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;
|
||||
}
|
||||
}
|
||||
@@ -83,8 +89,7 @@ char *FileNode_GetPath(FileNode *fileNode, char *path) {
|
||||
char *pathnodes[128];
|
||||
int levels, i;
|
||||
char *pathptr = temppath;
|
||||
if (path)
|
||||
pathptr = path;
|
||||
if (path) { pathptr = path; }
|
||||
|
||||
FileNode_GetPath_Rec(fileNode, pathnodes);
|
||||
levels = 0;
|
||||
@@ -99,6 +104,7 @@ char *FileNode_GetPath(FileNode *fileNode, char *path) {
|
||||
strcat(pathptr, fileNode->name);
|
||||
return temppath;
|
||||
}
|
||||
|
||||
char *FileNode_GetFullPath(FileNode *fileNode, char *basePath, char *path) {
|
||||
char *pathnodes[128];
|
||||
int levels, i;
|
||||
@@ -127,12 +133,12 @@ void FileNode_GetSize(FileNode *fileNode, char *file) {
|
||||
}
|
||||
|
||||
void FileNode_GetTime(FileNode *fileNode, char *file) {
|
||||
fileNode->flags |= FileFlag_HastTime;
|
||||
fileNode->flags |= FileFlag_HasTime;
|
||||
fileNode->fileTime = FileTime_Get(file);
|
||||
}
|
||||
|
||||
void FileNode_GetSizeAndTime(FileNode *fileNode, char *file) {
|
||||
fileNode->flags |= FileFlag_HasSize | FileFlag_HastTime;
|
||||
fileNode->flags |= FileFlag_HasSize | FileFlag_HasTime;
|
||||
File_GetSizeAndTime(file, &fileNode->size, &fileNode->fileTime);
|
||||
}
|
||||
|
||||
@@ -148,49 +154,58 @@ void FileNode_GetCRC(FileNode *fileNode, char *filePath) {
|
||||
}
|
||||
|
||||
void FileNode_SaveNode(FileNode *fileNode, FILE *file) {
|
||||
int name_len;
|
||||
short nameLen;
|
||||
|
||||
// Escribir nombre
|
||||
name_len = strlen(fileNode->name);
|
||||
fwrite((void *) &name_len, sizeof(name_len), 1, file);
|
||||
// Write name
|
||||
nameLen = strlen(fileNode->name);
|
||||
fwrite((void *)&nameLen, sizeof(nameLen), 1, file);
|
||||
if (nameLen>0 && nameLen<MaxFilename) {
|
||||
fputs(fileNode->name, file);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
// Escribir flags
|
||||
// Write flags
|
||||
fwrite((void *)&fileNode->flags, sizeof(fileNode->flags), 1, file);
|
||||
|
||||
// Escribir estado
|
||||
fputc((char) fileNode->estado, file);
|
||||
// Write status
|
||||
fputc((char)fileNode->status, file);
|
||||
|
||||
// Escribir tamanho
|
||||
// Write size
|
||||
if (fileNode->flags & FileFlag_HasSize) {
|
||||
fwrite((void *)&fileNode->size, sizeof(fileNode->size), 1, file);
|
||||
}
|
||||
|
||||
// Escribir fecha
|
||||
if (fileNode->flags & FileFlag_HastTime) {
|
||||
// Write date
|
||||
if (fileNode->flags & FileFlag_HasTime) {
|
||||
fwrite((void *)&fileNode->fileTime, sizeof(fileNode->fileTime), 1, file);
|
||||
}
|
||||
|
||||
// Escribir CRC
|
||||
// Write CRC
|
||||
if (fileNode->flags & FileFlag_HasCRC) {
|
||||
fwrite((void *)&fileNode->crc, sizeof(fileNode->crc), 1, file);
|
||||
}
|
||||
|
||||
// Escribir ficheros del directorio
|
||||
// Write files of directory
|
||||
if (fileNode->flags & FileFlag_Directory) {
|
||||
FileNode *fileNodeChild;
|
||||
fwrite((void *)&fileNode->childCount, sizeof(fileNode->childCount), 1, file);
|
||||
fileNodeChild = fileNode->child;
|
||||
int cnt = 0;
|
||||
while (fileNodeChild) {
|
||||
FileNode_SaveNode(fileNodeChild, file);
|
||||
fileNodeChild = fileNodeChild->next;
|
||||
cnt++;
|
||||
}
|
||||
if (fileNode->childCount != cnt) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FileNode_Save(FileNode *fileNode, char *filePath) {
|
||||
FILE *file;
|
||||
char marca[5];
|
||||
char mark[5];
|
||||
int version;
|
||||
|
||||
if (!fileNode)
|
||||
@@ -199,9 +214,9 @@ void FileNode_Save(FileNode *fileNode, char *filePath) {
|
||||
if (!file)
|
||||
return;
|
||||
|
||||
// Escribir marca y version
|
||||
strcpy(marca, "sYnC");
|
||||
fwrite((void *) marca, sizeof(char), 4, file);
|
||||
// Write mark and version
|
||||
strcpy(mark, "sYnC");
|
||||
fwrite((void *)mark, sizeof(char), 4, file);
|
||||
version = FileNode_Version;
|
||||
fwrite((void *)&version, sizeof(int), 1, file);
|
||||
|
||||
@@ -216,42 +231,54 @@ FileNode *FileNode_LoadNode(FILE *file) {
|
||||
|
||||
fileNode = FileNode_Create();
|
||||
|
||||
// Leer el nombre
|
||||
// Read name
|
||||
fread((void *)&nameLen, sizeof(nameLen), 1, file);
|
||||
fileNode->name[0] = 0;
|
||||
if (nameLen<0 || nameLen>MaxFilename) {
|
||||
FileNode_Delete(fileNode);
|
||||
return NULL;
|
||||
}
|
||||
if (nameLen > 0) {
|
||||
fread((void *)fileNode->name, sizeof(char), nameLen, file);
|
||||
fileNode->name[nameLen] = 0;
|
||||
}
|
||||
|
||||
// Leer vanderas
|
||||
// Read flags
|
||||
fread((void *)&fileNode->flags, sizeof(fileNode->flags), 1, file);
|
||||
|
||||
// Leer estado
|
||||
fileNode->estado = fgetc(file);
|
||||
fileNode->status = fgetc(file);
|
||||
|
||||
// Leer tamanho
|
||||
// Read status
|
||||
if (fileNode->flags & FileFlag_HasSize) {
|
||||
fread((void *)&fileNode->size, sizeof(fileNode->size), 1, file);
|
||||
}
|
||||
|
||||
// Leer fecha
|
||||
if (fileNode->flags & FileFlag_HastTime) {
|
||||
// Read date
|
||||
if (fileNode->flags & FileFlag_HasTime) {
|
||||
fread((void *)&fileNode->fileTime, sizeof(fileNode->fileTime), 1, file);
|
||||
}
|
||||
|
||||
// Leer CRC
|
||||
// Read CRC
|
||||
if (fileNode->flags & FileFlag_HasCRC) {
|
||||
fread((void *)&fileNode->crc, sizeof(fileNode->crc), 1, file);
|
||||
}
|
||||
|
||||
// Leer ficheros del directorio
|
||||
// Read files on directory
|
||||
if (fileNode->flags & FileFlag_Directory) {
|
||||
FileNode *fileNodeChildAux = NULL, *fileNodeChild;
|
||||
fread((void *)&fileNode->childCount, sizeof(fileNode->childCount), 1, file);
|
||||
for (i = 0; i < fileNode->childCount; i++) {
|
||||
fileNodeChild = FileNode_LoadNode(file);
|
||||
if (fileNodeChild == NULL) {
|
||||
// FIXME: Clean memory (fileNode, fileNodeChild etc)
|
||||
return NULL;
|
||||
}
|
||||
fileNodeChild->parent = fileNode;
|
||||
if (!fileNodeChildAux) {
|
||||
fileNode->child = fileNodeChild;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
fileNodeChildAux->next = fileNodeChild;
|
||||
}
|
||||
fileNodeChildAux = fileNodeChild;
|
||||
@@ -271,17 +298,17 @@ FileNode *FileNode_Load(char *filePath) {
|
||||
if (!file)
|
||||
return (NULL);
|
||||
|
||||
// Leer marca y version
|
||||
// Read mark and version
|
||||
fread((void *)mark, sizeof(char), 4, file);
|
||||
mark[4] = 0;
|
||||
if (strcmp(mark, "sYnC")) {
|
||||
// Marca incorrecta
|
||||
// Incorrect mark
|
||||
fclose(file);
|
||||
return (NULL);
|
||||
}
|
||||
fread((void *)&version, sizeof(int), 1, file);
|
||||
if (version != FileNode_Version) {
|
||||
// Version incorrecta
|
||||
// Incorrect version
|
||||
fclose(file);
|
||||
return (NULL);
|
||||
}
|
||||
@@ -296,26 +323,27 @@ void FileNode_PrintNode(FileNode *fileNode) {
|
||||
printff(FileNode_GetPath(fileNode, NULL));
|
||||
if (fileNode->flags & FileFlag_Normal) {
|
||||
printff(" File");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printff(" Dir");
|
||||
}
|
||||
printff(" %d", fileNode->estado);
|
||||
if (fileNode->estado == FileStatus_New) {
|
||||
printff(" Nuevo");
|
||||
printff(" %d", fileNode->status);
|
||||
if (fileNode->status == FileStatus_New) {
|
||||
printff(" New");
|
||||
}
|
||||
if (fileNode->estado == FileStatus_Modified) {
|
||||
printff(" Modificado");
|
||||
if (fileNode->status == FileStatus_Modified) {
|
||||
printff(" Modified");
|
||||
}
|
||||
if (fileNode->estado == FileStatus_Deleted) {
|
||||
printff(" Borrado!!!");
|
||||
if (fileNode->status == FileStatus_Deleted) {
|
||||
printff(" Deleted!!!");
|
||||
}
|
||||
printff("\n");
|
||||
|
||||
if (fileNode->flags&FileFlag_HasSize) {
|
||||
printff("\\-Tamanho: %lld\n",fileNode->size);
|
||||
printff("\\-Size : %lld\n", fileNode->size);
|
||||
}
|
||||
if(fileNode->flags&FileFlag_HastTime){
|
||||
printff("\\-Fecha : ");FileTime_Print(fileNode->fileTime);printff("\n");
|
||||
if (fileNode->flags&FileFlag_HasTime) {
|
||||
printff("\\-Date : "); FileTime_Print(fileNode->fileTime); printff("\n");
|
||||
}
|
||||
if (fileNode->flags&FileFlag_HasCRC) {
|
||||
printff("\\-CRC : [%08X]\n", fileNode->crc);
|
||||
@@ -335,7 +363,8 @@ 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) {
|
||||
@@ -359,18 +388,18 @@ FileNode *FileNode_Build(char *path) {
|
||||
if (!File_ExistsPath(path))
|
||||
return (NULL);
|
||||
|
||||
// Crear el nodo
|
||||
// Create node
|
||||
fileNode = FileNode_Create();
|
||||
File_GetName(path, fileNode->name);
|
||||
|
||||
// Determinar si es un fichero o directorio
|
||||
if (File_IsDirectory(path)) {
|
||||
// Obtener datos para los directorios
|
||||
// Get information data from directories, and child files
|
||||
fileNode->flags |= FileFlag_Directory;
|
||||
FileNode_GetTime(fileNode, path);
|
||||
File_IterateDir(path, FileNode_Build_Iterate, fileNode);
|
||||
} else {
|
||||
// Obtener datos para los ficheros
|
||||
}
|
||||
else {
|
||||
// Get information data from files
|
||||
fileNode->flags |= FileFlag_Normal;
|
||||
FileNode_GetSizeAndTime(fileNode, path);
|
||||
}
|
||||
@@ -380,7 +409,6 @@ FileNode *FileNode_Build(char *path) {
|
||||
|
||||
int FileNode_Build_Iterate(char *path, char *name, void *d) {
|
||||
FileNode *fileNode, *fileNodeParent = d;
|
||||
;
|
||||
|
||||
if (!strcmp(name, FileNode_Filename)) {
|
||||
return (0);
|
||||
@@ -401,20 +429,21 @@ FileNode *FileNode_Refresh(FileNode *fileNode, char *filePath) {
|
||||
fileNode = FileNode_Create();
|
||||
File_GetName(filePath, fileNode->name);
|
||||
}
|
||||
FileNode_SetEstadoRec(fileNode, FileStatus_Deleted);
|
||||
FileNode_SetStatusRec(fileNode, FileStatus_Deleted);
|
||||
return (fileNode);
|
||||
}
|
||||
if (!fileNode) {
|
||||
// El fichero ha sido creado
|
||||
fileNode = FileNode_Build(filePath);
|
||||
FileNode_SetEstadoRec(fileNode, FileStatus_New);
|
||||
} else {
|
||||
FileNode_SetStatusRec(fileNode, FileStatus_New);
|
||||
}
|
||||
else {
|
||||
// Comprobar si ha sido modificado
|
||||
FileTime fileTime;
|
||||
long long size;
|
||||
|
||||
// Marcar normal
|
||||
fileNode->estado = FileStatus_None;
|
||||
fileNode->status = FileStatus_None;
|
||||
fileNode->flags &= ~FileFlag_MarkerForReview;
|
||||
|
||||
// Determinar si es un fichero o directorio
|
||||
@@ -423,13 +452,13 @@ FileNode *FileNode_Refresh(FileNode *fileNode, char *filePath) {
|
||||
|
||||
// Comparar datos de los directorios
|
||||
if (!(fileNode->flags & FileFlag_Directory)) {
|
||||
fileNode->estado = FileStatus_Modified;
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->flags |= FileFlag_Directory;
|
||||
fileNode->flags &= ~FileFlag_Normal;
|
||||
}
|
||||
fileTime = FileTime_Get(filePath);
|
||||
if (fileTime != fileNode->fileTime) {
|
||||
fileNode->estado = FileStatus_Modified;
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->fileTime = fileTime;
|
||||
}
|
||||
|
||||
@@ -448,27 +477,28 @@ FileNode *FileNode_Refresh(FileNode *fileNode, char *filePath) {
|
||||
while (fileNodeChild) {
|
||||
if (fileNodeChild->flags & FileFlag_MarkerForReview) {
|
||||
fileNodeChild->flags &= ~FileFlag_MarkerForReview;
|
||||
FileNode_SetEstadoRec(fileNodeChild, FileStatus_Deleted);
|
||||
FileNode_SetStatusRec(fileNodeChild, FileStatus_Deleted);
|
||||
}
|
||||
fileNodeChild = fileNodeChild->next;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Comprar datos de los ficheros
|
||||
if (!(fileNode->flags & FileFlag_Normal)) {
|
||||
fileNode->estado = FileStatus_Modified;
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->flags |= FileFlag_Normal;
|
||||
fileNode->flags &= ~FileFlag_Directory;
|
||||
}
|
||||
File_GetSizeAndTime(filePath, &size, &fileTime);
|
||||
if (size != fileNode->size) {
|
||||
fileNode->estado = FileStatus_Modified;
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->size = size;
|
||||
}
|
||||
if (fileTime != fileNode->fileTime) {
|
||||
fileNode->estado = FileStatus_Modified;
|
||||
fileNode->status = FileStatus_Modified;
|
||||
fileNode->fileTime = fileTime;
|
||||
}
|
||||
if (fileNode->estado == FileStatus_Modified) {
|
||||
if (fileNode->status == FileStatus_Modified) {
|
||||
fileNode->flags &= ~FileFlag_HasCRC;
|
||||
}
|
||||
}
|
||||
@@ -495,7 +525,8 @@ int FileNode_Refresh_Iterate(char *path, char *name, void *d) {
|
||||
if (fileNodeChild) {
|
||||
// Existe, refrescar
|
||||
FileNode_Refresh(fileNodeChild, path);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// Nuevo, construir
|
||||
fileNodeChild = FileNode_Refresh(NULL, path);
|
||||
FileNode_AddChild(fileNode, fileNodeChild);
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#define FileFlag_Normal 2
|
||||
#define FileFlag_Directory 4
|
||||
#define FileFlag_HasSize 8
|
||||
#define FileFlag_HastTime 16
|
||||
#define FileFlag_HasTime 16
|
||||
#define FileFlag_HasCRC 32
|
||||
#define FileFlag_MarkerForReview 1024
|
||||
|
||||
@@ -23,7 +23,7 @@ typedef enum {
|
||||
typedef struct SFileNode {
|
||||
char name[MaxFilename];
|
||||
int flags;
|
||||
FileStatus estado;
|
||||
FileStatus status;
|
||||
|
||||
long long size;
|
||||
unsigned long crc;
|
||||
|
||||
@@ -12,17 +12,20 @@ int maxDeltaTime = 4000;
|
||||
|
||||
#define QueueNode(queue,node) (queue)->next = node; (queue) = node;
|
||||
|
||||
AccionFileNode *_actionFileNodeFree = NULL;
|
||||
ActionFileNode *_actionFileNodeFree = NULL;
|
||||
#define AccionFileNode_Tocho 1024
|
||||
AccionFileNode *AccionFileNode_Create() {
|
||||
AccionFileNode *actionFileNode;
|
||||
ActionFileNode *ActionFileNode_Create() {
|
||||
ActionFileNode *actionFileNode;
|
||||
|
||||
if (_actionFileNodeFree == NULL) {
|
||||
AccionFileNode *actionFileNodeFreeAux;
|
||||
ActionFileNode *actionFileNodeFreeAux;
|
||||
int i;
|
||||
// Reservar un tocho
|
||||
actionFileNodeFreeAux = malloc(
|
||||
sizeof(AccionFileNode) * AccionFileNode_Tocho);
|
||||
sizeof(ActionFileNode) * AccionFileNode_Tocho);
|
||||
if (actionFileNodeFreeAux == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i < AccionFileNode_Tocho - 1; i++) {
|
||||
actionFileNodeFreeAux[i].next = &actionFileNodeFreeAux[i + 1];
|
||||
}
|
||||
@@ -35,7 +38,7 @@ AccionFileNode *AccionFileNode_Create() {
|
||||
_actionFileNodeFree = actionFileNode->next;
|
||||
|
||||
// Iniciar
|
||||
actionFileNode->action = AccionFileCmp_Nothing;
|
||||
actionFileNode->action = ActionFileCmp_Nothing;
|
||||
actionFileNode->left = NULL;
|
||||
actionFileNode->right = NULL;
|
||||
actionFileNode->next = NULL;
|
||||
@@ -43,26 +46,26 @@ AccionFileNode *AccionFileNode_Create() {
|
||||
return (actionFileNode);
|
||||
}
|
||||
|
||||
void AccionFileNode_Destroy(AccionFileNode *actionFileNode) {
|
||||
void AccionFileNode_Destroy(ActionFileNode *actionFileNode) {
|
||||
actionFileNode->next = _actionFileNodeFree;
|
||||
_actionFileNodeFree = actionFileNode;
|
||||
}
|
||||
|
||||
AccionFileNode *AccionFileNode_CreateNormal(FileNode *fileNodeLeft,
|
||||
ActionFileNode *ActionFileNode_CreateNormal(FileNode *fileNodeLeft,
|
||||
FileNode *fileNodeRight) {
|
||||
AccionFileNode *actionFileNode;
|
||||
actionFileNode = AccionFileNode_Create();
|
||||
actionFileNode->action = AccionFileCmp_Nothing;
|
||||
ActionFileNode *actionFileNode;
|
||||
actionFileNode = ActionFileNode_Create();
|
||||
actionFileNode->action = ActionFileCmp_Nothing;
|
||||
actionFileNode->left = fileNodeLeft;
|
||||
actionFileNode->right = fileNodeRight;
|
||||
return actionFileNode;
|
||||
}
|
||||
|
||||
|
||||
void AccionFileNode_CompareChilds(AccionFileNode *actionFileNodeRoot,
|
||||
AccionFileNode **actionFileNodeQueue,
|
||||
void AccionFileNode_CompareChilds(ActionFileNode *actionFileNodeRoot,
|
||||
ActionFileNode **actionFileNodeQueue,
|
||||
void(*CheckPair)(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
AccionFileNode **actionFileNodeQueue)) {
|
||||
ActionFileNode **actionFileNodeQueue)) {
|
||||
FileNode *fileNodeLeft;
|
||||
FileNode *fileNodeRight;
|
||||
FileNode *fileNodeRightQueue;
|
||||
@@ -112,7 +115,8 @@ void AccionFileNode_CompareChilds(AccionFileNode *actionFileNodeRoot,
|
||||
// Match, extract right child FileNode to the processed chain
|
||||
if (fileNodeRightPrevious) {
|
||||
fileNodeRightPrevious->next = fileNodeRight->next;
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
fileNodeRightQueue = fileNodeRight->next;
|
||||
}
|
||||
fileNodeRight->next = fileNodeRightProcessed;
|
||||
@@ -120,7 +124,8 @@ void AccionFileNode_CompareChilds(AccionFileNode *actionFileNodeRoot,
|
||||
|
||||
CheckPair(fileNodeLeft, fileNodeRight, actionFileNodeQueue);
|
||||
break;
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
// Next right child
|
||||
fileNodeRightPrevious = fileNodeRight;
|
||||
fileNodeRight = fileNodeRight->next;
|
||||
@@ -146,8 +151,8 @@ void AccionFileNode_CompareChilds(AccionFileNode *actionFileNodeRoot,
|
||||
}
|
||||
|
||||
void AccionFileNode_DeletePair(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
AccionFileNode **actionFileNodeQueue) {
|
||||
AccionFileNode *actionFileNodeNew = AccionFileNode_CreateNormal(
|
||||
ActionFileNode **actionFileNodeQueue) {
|
||||
ActionFileNode *actionFileNodeNew = ActionFileNode_CreateNormal(
|
||||
fileNodeLeft, fileNodeRight);
|
||||
|
||||
if (!fileNodeLeft && !fileNodeRight) {
|
||||
@@ -161,11 +166,12 @@ void AccionFileNode_DeletePair(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
AccionFileNode_DeletePair);
|
||||
}
|
||||
|
||||
if (fileNodeRight->estado != FileStatus_Deleted) {
|
||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||
// Accion de borrado para el nodo
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteRight;
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
AccionFileNode_Destroy(actionFileNodeNew);
|
||||
}
|
||||
}
|
||||
@@ -176,11 +182,12 @@ void AccionFileNode_DeletePair(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
AccionFileNode_DeletePair);
|
||||
}
|
||||
|
||||
if (fileNodeLeft->estado != FileStatus_Deleted) {
|
||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||
// Accion de borrado para el nodo
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteLeft;
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
AccionFileNode_Destroy(actionFileNodeNew);
|
||||
}
|
||||
}
|
||||
@@ -194,19 +201,19 @@ void AccionFileNode_DeletePair(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
AccionFileNode_DeletePair);
|
||||
}
|
||||
|
||||
if (fileNodeLeft->estado != FileStatus_Deleted) {
|
||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||
// Accion de borrado para el nodo izquierdo
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteLeft;
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
actionFileNodeNew = NULL;
|
||||
}
|
||||
if (fileNodeRight->estado != FileStatus_Deleted) {
|
||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||
if (!actionFileNodeNew) {
|
||||
actionFileNodeNew = AccionFileNode_CreateNormal(fileNodeLeft,
|
||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
||||
fileNodeRight);
|
||||
}
|
||||
// Accion de borrado para el nodo derecho
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteRight;
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
actionFileNodeNew = NULL;
|
||||
}
|
||||
@@ -217,8 +224,8 @@ void AccionFileNode_DeletePair(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
}
|
||||
|
||||
void AccionFileNode_CheckPair(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
AccionFileNode **actionFileNodeQueue) {
|
||||
AccionFileNode *actionFileNodeNew = AccionFileNode_CreateNormal(
|
||||
ActionFileNode **actionFileNodeQueue) {
|
||||
ActionFileNode *actionFileNodeNew = ActionFileNode_CreateNormal(
|
||||
fileNodeLeft, fileNodeRight);
|
||||
|
||||
if (!fileNodeLeft && !fileNodeRight) {
|
||||
@@ -228,11 +235,12 @@ void AccionFileNode_CheckPair(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
if (!fileNodeLeft && fileNodeRight) {
|
||||
if (fileNodeRight->flags & FileFlag_Directory) {
|
||||
// Directory
|
||||
if (fileNodeRight->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
} else {
|
||||
actionFileNodeNew->action = AccionFileCmp_MakeLeftDirectory;
|
||||
}
|
||||
else {
|
||||
actionFileNodeNew->action = ActionFileCmp_MakeLeftDirectory;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
|
||||
// Iterar hijos
|
||||
@@ -240,17 +248,19 @@ void AccionFileNode_CheckPair(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
actionFileNodeQueue, AccionFileNode_CheckPair);
|
||||
|
||||
// Crear nueva accion para copiar la fecha
|
||||
actionFileNodeNew = AccionFileNode_CreateNormal(fileNodeLeft,
|
||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
||||
fileNodeRight);
|
||||
actionFileNodeNew->action = AccionFileCmp_DateRightToLeft;
|
||||
actionFileNodeNew->action = ActionFileCmp_DateRightToLeft;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// File
|
||||
if (fileNodeRight->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
} else {
|
||||
actionFileNodeNew->action = AccionFileCmp_RightToLeft;
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
else {
|
||||
actionFileNodeNew->action = ActionFileCmp_RightToLeft;
|
||||
}
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
@@ -258,11 +268,12 @@ void AccionFileNode_CheckPair(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
if (fileNodeLeft && !fileNodeRight) {
|
||||
if (fileNodeLeft->flags & FileFlag_Directory) {
|
||||
// Directory
|
||||
if (fileNodeLeft->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
} else {
|
||||
actionFileNodeNew->action = AccionFileCmp_MakeRightDirectory;
|
||||
}
|
||||
else {
|
||||
actionFileNodeNew->action = ActionFileCmp_MakeRightDirectory;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
|
||||
// Iterar hijos
|
||||
@@ -270,17 +281,19 @@ void AccionFileNode_CheckPair(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
actionFileNodeQueue, AccionFileNode_CheckPair);
|
||||
|
||||
// Crear nueva accion para copiar la fecha
|
||||
actionFileNodeNew = AccionFileNode_CreateNormal(fileNodeLeft,
|
||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
||||
fileNodeRight);
|
||||
actionFileNodeNew->action = AccionFileCmp_DateLeftToRight;
|
||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// File
|
||||
if (fileNodeLeft->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
} else {
|
||||
actionFileNodeNew->action = AccionFileCmp_LeftToRight;
|
||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
else {
|
||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||
}
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
@@ -292,96 +305,109 @@ void AccionFileNode_CheckPair(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
|
||||
// Preparar accion para el par de directorios
|
||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime)) <= maxDeltaTime) { // appoximadamente iguales
|
||||
if (fileNodeRight->estado == FileStatus_Deleted
|
||||
&& fileNodeLeft->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
} else if (fileNodeRight->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteLeft;
|
||||
if (fileNodeLeft->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
if (fileNodeRight->status == FileStatus_Deleted
|
||||
&& fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
} else if (fileNodeLeft->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteRight;
|
||||
if (fileNodeRight->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
} else {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
} else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DateRightToLeft;
|
||||
if (fileNodeRight->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteLeft;
|
||||
if (fileNodeLeft->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
else if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
} else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DateLeftToRight;
|
||||
if (fileNodeLeft->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteRight;
|
||||
if (fileNodeRight->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
else if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
else {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DateRightToLeft;
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Procesar nodos hijos
|
||||
if (actionFileNodeNew->action == AccionFileCmp_DeleteRight
|
||||
|| actionFileNodeNew->action == AccionFileCmp_DeleteLeft
|
||||
|| (fileNodeLeft->estado == FileStatus_Deleted
|
||||
&& fileNodeRight->estado == FileStatus_Deleted)) {
|
||||
if (actionFileNodeNew->action == ActionFileCmp_DeleteRight
|
||||
|| actionFileNodeNew->action == ActionFileCmp_DeleteLeft
|
||||
|| (fileNodeLeft->status == FileStatus_Deleted
|
||||
&& fileNodeRight->status == FileStatus_Deleted)) {
|
||||
// Iterar nodos hijos para borrarlos
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||
actionFileNodeQueue, AccionFileNode_DeletePair);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||
actionFileNodeQueue, AccionFileNode_CheckPair);
|
||||
}
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
} else if ((fileNodeLeft->flags & FileFlag_Normal)
|
||||
}
|
||||
else if ((fileNodeLeft->flags & FileFlag_Normal)
|
||||
&& (fileNodeRight->flags & FileFlag_Normal)) {
|
||||
// Ficheros
|
||||
|
||||
// Preparar accion para el par de ficheros
|
||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime)) <= maxDeltaTime) { // appoximadamente iguales
|
||||
if (fileNodeRight->estado == FileStatus_Deleted
|
||||
&& fileNodeLeft->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
} else if (fileNodeRight->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteLeft;
|
||||
if (fileNodeLeft->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
if (fileNodeRight->status == FileStatus_Deleted
|
||||
&& fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
} else if (fileNodeLeft->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteRight;
|
||||
if (fileNodeRight->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
else if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
} else {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
} else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
||||
else if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
else {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
else if (fileNodeLeft->fileTime < fileNodeRight->fileTime) {
|
||||
// FIXME: Check size to determine y further checks are necessary
|
||||
actionFileNodeNew->action = AccionFileCmp_RightToLeft;
|
||||
if (fileNodeRight->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteLeft;
|
||||
if (fileNodeLeft->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
actionFileNodeNew->action = ActionFileCmp_RightToLeft;
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteLeft;
|
||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
} else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
||||
}
|
||||
else if (fileNodeLeft->fileTime > fileNodeRight->fileTime) {
|
||||
// FIXME: Check size to determine y further checks are necessary
|
||||
actionFileNodeNew->action = AccionFileCmp_LeftToRight;
|
||||
if (fileNodeLeft->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteRight;
|
||||
if (fileNodeRight->estado == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||
if (fileNodeLeft->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
if (fileNodeRight->status == FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
}
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// FIXME: !!!!!
|
||||
// Directory vs File
|
||||
|
||||
@@ -389,18 +415,18 @@ void AccionFileNode_CheckPair(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
}
|
||||
}
|
||||
|
||||
AccionFileNode *AccionFileNode_BuildSync(FileNode *izquierda, FileNode *derecha) {
|
||||
AccionFileNode *actionFileNodeRoot = AccionFileNode_CreateNormal(izquierda,
|
||||
ActionFileNode *ActionFileNode_BuildSync(FileNode *izquierda, FileNode *derecha) {
|
||||
ActionFileNode *actionFileNodeRoot = ActionFileNode_CreateNormal(izquierda,
|
||||
derecha);
|
||||
AccionFileNode *actionFileNodeQueue = actionFileNodeRoot;
|
||||
ActionFileNode *actionFileNodeQueue = actionFileNodeRoot;
|
||||
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
||||
AccionFileNode_CheckPair);
|
||||
return actionFileNodeRoot;
|
||||
}
|
||||
|
||||
void AccionFileNode_Copy(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
AccionFileNode **actionFileNodeQueue) {
|
||||
AccionFileNode *actionFileNodeNew = AccionFileNode_CreateNormal(
|
||||
ActionFileNode **actionFileNodeQueue) {
|
||||
ActionFileNode *actionFileNodeNew = ActionFileNode_CreateNormal(
|
||||
fileNodeLeft, fileNodeRight);
|
||||
|
||||
if (!fileNodeLeft && !fileNodeRight) {
|
||||
@@ -413,62 +439,70 @@ void AccionFileNode_Copy(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
AccionFileNode_DeletePair);
|
||||
}
|
||||
|
||||
if (fileNodeRight->estado != FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteRight;
|
||||
} else {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
}
|
||||
else {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
if (fileNodeLeft && !fileNodeRight) {
|
||||
if (fileNodeLeft->estado != FileStatus_Deleted) {
|
||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||
if (fileNodeLeft->flags & FileFlag_Directory) {
|
||||
actionFileNodeNew->action = AccionFileCmp_MakeRightDirectory;
|
||||
actionFileNodeNew->action = ActionFileCmp_MakeRightDirectory;
|
||||
(*actionFileNodeQueue)->next = actionFileNodeNew;
|
||||
(*actionFileNodeQueue) = actionFileNodeNew;
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||
actionFileNodeQueue, AccionFileNode_Copy);
|
||||
actionFileNodeNew = AccionFileNode_CreateNormal(fileNodeLeft,
|
||||
actionFileNodeNew = ActionFileNode_CreateNormal(fileNodeLeft,
|
||||
fileNodeRight);
|
||||
actionFileNodeNew->action = AccionFileCmp_DateLeftToRight;
|
||||
} else {
|
||||
actionFileNodeNew->action = AccionFileCmp_LeftToRight;
|
||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||
}
|
||||
} else {
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
else {
|
||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||
}
|
||||
}
|
||||
else {
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
QueueNode(*actionFileNodeQueue, actionFileNodeNew);
|
||||
}
|
||||
if (fileNodeLeft && fileNodeRight) {
|
||||
if ((fileNodeLeft->flags & FileFlag_Directory)
|
||||
|| (fileNodeRight->flags & FileFlag_Directory)) {
|
||||
if (fileNodeLeft->estado != FileStatus_Deleted) {
|
||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||
actionFileNodeQueue, AccionFileNode_Copy);
|
||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime))
|
||||
<= maxDeltaTime) { // appox. equal
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
} else {
|
||||
actionFileNodeNew->action = AccionFileCmp_DateLeftToRight;
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
} else {
|
||||
else {
|
||||
actionFileNodeNew->action = ActionFileCmp_DateLeftToRight;
|
||||
}
|
||||
}
|
||||
else {
|
||||
AccionFileNode_CompareChilds(actionFileNodeNew,
|
||||
actionFileNodeQueue, AccionFileNode_DeletePair);
|
||||
if (fileNodeRight->estado != FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteRight;
|
||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (fileNodeLeft->estado != FileStatus_Deleted) {
|
||||
}
|
||||
else {
|
||||
if (fileNodeLeft->status != FileStatus_Deleted) {
|
||||
if (abs((int)(fileNodeLeft->fileTime - fileNodeRight->fileTime))
|
||||
<= maxDeltaTime) { // appox. equal
|
||||
actionFileNodeNew->action = AccionFileCmp_Nothing;
|
||||
} else {
|
||||
actionFileNodeNew->action = AccionFileCmp_LeftToRight;
|
||||
actionFileNodeNew->action = ActionFileCmp_Nothing;
|
||||
}
|
||||
} else {
|
||||
if (fileNodeRight->estado != FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = AccionFileCmp_DeleteRight;
|
||||
else {
|
||||
actionFileNodeNew->action = ActionFileCmp_LeftToRight;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (fileNodeRight->status != FileStatus_Deleted) {
|
||||
actionFileNodeNew->action = ActionFileCmp_DeleteRight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -476,17 +510,17 @@ void AccionFileNode_Copy(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
}
|
||||
}
|
||||
|
||||
AccionFileNode *AccionFileNode_BuildCopy(FileNode *fileNodeLeft,
|
||||
ActionFileNode *ActionFileNode_BuildCopy(FileNode *fileNodeLeft,
|
||||
FileNode *fileNodeRight) {
|
||||
AccionFileNode *actionFileNodeRoot = AccionFileNode_CreateNormal(
|
||||
ActionFileNode *actionFileNodeRoot = ActionFileNode_CreateNormal(
|
||||
fileNodeLeft, fileNodeRight);
|
||||
AccionFileNode *actionFileNodeQueue = actionFileNodeRoot;
|
||||
ActionFileNode *actionFileNodeQueue = actionFileNodeRoot;
|
||||
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
||||
AccionFileNode_Copy);
|
||||
return actionFileNodeRoot;
|
||||
}
|
||||
|
||||
void AccionFileNode_Statistics(AccionFileNode *actionFileNode,
|
||||
void ActionFileNode_Statistics(ActionFileNode *actionFileNode,
|
||||
ActionQueueStatistics *statistics) {
|
||||
statistics->readLeft = 0;
|
||||
statistics->writeLeft = 0;
|
||||
@@ -502,36 +536,36 @@ void AccionFileNode_Statistics(AccionFileNode *actionFileNode,
|
||||
while (actionFileNode != NULL) {
|
||||
|
||||
switch (actionFileNode->action) {
|
||||
case AccionFileCmp_Nothing:
|
||||
case ActionFileCmp_Nothing:
|
||||
break;
|
||||
case AccionFileCmp_LeftToRight:
|
||||
case ActionFileCmp_LeftToRight:
|
||||
statistics->fullCopyCount++;
|
||||
statistics->readLeft += actionFileNode->left->size;
|
||||
statistics->writeRight += actionFileNode->left->size;
|
||||
break;
|
||||
case AccionFileCmp_RightToLeft:
|
||||
case ActionFileCmp_RightToLeft:
|
||||
statistics->fullCopyCount++;
|
||||
statistics->writeLeft += actionFileNode->right->size;
|
||||
statistics->readRight += actionFileNode->right->size;
|
||||
break;
|
||||
case AccionFileCmp_DeleteLeft:
|
||||
case ActionFileCmp_DeleteLeft:
|
||||
statistics->deleteCount++;
|
||||
statistics->deleteLeft += actionFileNode->left->size;
|
||||
break;
|
||||
case AccionFileCmp_DeleteRight:
|
||||
case ActionFileCmp_DeleteRight:
|
||||
statistics->deleteCount++;
|
||||
statistics->deleteRight += actionFileNode->right->size;
|
||||
break;
|
||||
case AccionFileCmp_DateLeftToRight:
|
||||
case ActionFileCmp_DateLeftToRight:
|
||||
statistics->dateCopyCount++;
|
||||
break;
|
||||
case AccionFileCmp_DateRightToLeft:
|
||||
case ActionFileCmp_DateRightToLeft:
|
||||
statistics->dateCopyCount++;
|
||||
break;
|
||||
case AccionFileCmp_MakeRightDirectory:
|
||||
case ActionFileCmp_MakeRightDirectory:
|
||||
statistics->directoryCount++;
|
||||
break;
|
||||
case AccionFileCmp_MakeLeftDirectory:
|
||||
case ActionFileCmp_MakeLeftDirectory:
|
||||
statistics->directoryCount++;
|
||||
break;
|
||||
}
|
||||
@@ -540,41 +574,42 @@ void AccionFileNode_Statistics(AccionFileNode *actionFileNode,
|
||||
}
|
||||
}
|
||||
|
||||
void AccionFileNode_Print(AccionFileNode *actionFileNode) {
|
||||
void ActionFileNode_Print(ActionFileNode *actionFileNode) {
|
||||
char showPath[MaxPath];
|
||||
while (actionFileNode != NULL) {
|
||||
if (actionFileNode->left) {
|
||||
FileNode_GetFullPath(actionFileNode->left, "", showPath);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
FileNode_GetFullPath(actionFileNode->right, "", showPath);
|
||||
}
|
||||
|
||||
switch (actionFileNode->action) {
|
||||
case AccionFileCmp_Nothing:
|
||||
case ActionFileCmp_Nothing:
|
||||
//printff("%s == %s\n",pathIzq,pathDer);
|
||||
break;
|
||||
case AccionFileCmp_LeftToRight:
|
||||
case ActionFileCmp_LeftToRight:
|
||||
printff(" => %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_RightToLeft:
|
||||
case ActionFileCmp_RightToLeft:
|
||||
printff(" <= %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_DeleteLeft:
|
||||
case ActionFileCmp_DeleteLeft:
|
||||
printff(" *- %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_DeleteRight:
|
||||
case ActionFileCmp_DeleteRight:
|
||||
printff(" -* %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_DateLeftToRight:
|
||||
case ActionFileCmp_DateLeftToRight:
|
||||
printff(" -> %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_DateRightToLeft:
|
||||
case ActionFileCmp_DateRightToLeft:
|
||||
printff(" <- %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_MakeRightDirectory:
|
||||
case ActionFileCmp_MakeRightDirectory:
|
||||
printff(" -D %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_MakeLeftDirectory:
|
||||
case ActionFileCmp_MakeLeftDirectory:
|
||||
printff(" D- %s\n", showPath);
|
||||
break;
|
||||
}
|
||||
@@ -592,14 +627,16 @@ 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);
|
||||
}
|
||||
}
|
||||
void AccionFileNodeAux_Delete(char *pathOrig, char *pathDest) {
|
||||
if (File_IsDirectory(pathDest)) {
|
||||
File_DeleteDirectory(pathDest);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
File_Delete(pathDest);
|
||||
}
|
||||
}
|
||||
@@ -607,61 +644,64 @@ void AccionFileNodeAux_MakeDir(char *pathOrig, char *pathDest) {
|
||||
File_MakeDirectory(pathDest);
|
||||
}
|
||||
|
||||
void AccionFileNode_RunList(AccionFileNode *actionFileNode, char *pathLeft,
|
||||
void ActionFileNode_RunList(ActionFileNode *actionFileNode, char *pathLeft,
|
||||
char *pathRight) {
|
||||
char fullPathLeft[MaxPath], fullPathRight[MaxPath], showPath[MaxPath];
|
||||
while (actionFileNode != NULL) {
|
||||
if (actionFileNode->left) {
|
||||
FileNode_GetFullPath(actionFileNode->left, pathLeft, fullPathLeft);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
FileNode_GetFullPath(actionFileNode->right, pathLeft, fullPathLeft);
|
||||
}
|
||||
if (actionFileNode->right) {
|
||||
FileNode_GetFullPath(actionFileNode->right, pathRight,
|
||||
fullPathRight);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
FileNode_GetFullPath(actionFileNode->left, pathRight,
|
||||
fullPathRight);
|
||||
}
|
||||
if (actionFileNode->left) {
|
||||
FileNode_GetFullPath(actionFileNode->left, "", showPath);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
FileNode_GetFullPath(actionFileNode->right, "", showPath);
|
||||
}
|
||||
|
||||
switch (actionFileNode->action) {
|
||||
case AccionFileCmp_Nothing:
|
||||
case ActionFileCmp_Nothing:
|
||||
//printff("%s == %s\n",pathIzq,pathDer);
|
||||
break;
|
||||
case AccionFileCmp_LeftToRight:
|
||||
case ActionFileCmp_LeftToRight:
|
||||
printff(" => %s\n", showPath);
|
||||
AccionFileNodeAux_Copy(fullPathLeft, fullPathRight);
|
||||
break;
|
||||
case AccionFileCmp_RightToLeft:
|
||||
case ActionFileCmp_RightToLeft:
|
||||
printff(" <= %s\n", showPath);
|
||||
AccionFileNodeAux_Copy(fullPathRight, fullPathLeft);
|
||||
break;
|
||||
case AccionFileCmp_DeleteLeft:
|
||||
case ActionFileCmp_DeleteLeft:
|
||||
printff(" *- %s\n", showPath);
|
||||
AccionFileNodeAux_Delete(fullPathRight, fullPathLeft);
|
||||
break;
|
||||
case AccionFileCmp_DeleteRight:
|
||||
case ActionFileCmp_DeleteRight:
|
||||
printff(" -* %s\n", showPath);
|
||||
AccionFileNodeAux_Delete(fullPathLeft, fullPathRight);
|
||||
break;
|
||||
case AccionFileCmp_DateLeftToRight:
|
||||
case ActionFileCmp_DateLeftToRight:
|
||||
printff(" -> %s\n", showPath);
|
||||
AccionFileNodeAux_CopyDate(fullPathLeft, fullPathRight);
|
||||
break;
|
||||
case AccionFileCmp_DateRightToLeft:
|
||||
case ActionFileCmp_DateRightToLeft:
|
||||
printff(" <- %s\n", showPath);
|
||||
AccionFileNodeAux_CopyDate(fullPathRight, fullPathLeft);
|
||||
break;
|
||||
case AccionFileCmp_MakeRightDirectory:
|
||||
case ActionFileCmp_MakeRightDirectory:
|
||||
printff(" -D %s\n", showPath);
|
||||
AccionFileNodeAux_MakeDir(fullPathLeft, fullPathRight);
|
||||
break;
|
||||
case AccionFileCmp_MakeLeftDirectory:
|
||||
case ActionFileCmp_MakeLeftDirectory:
|
||||
printff(" D- %s\n", showPath);
|
||||
AccionFileNodeAux_MakeDir(fullPathRight, fullPathLeft);
|
||||
break;
|
||||
|
||||
@@ -4,32 +4,32 @@
|
||||
#include "filenode.h"
|
||||
|
||||
typedef enum {
|
||||
AccionFileCmp_Nothing,
|
||||
AccionFileCmp_LeftToRight,
|
||||
AccionFileCmp_RightToLeft,
|
||||
AccionFileCmp_DeleteLeft,
|
||||
AccionFileCmp_DeleteRight,
|
||||
AccionFileCmp_DateLeftToRight,
|
||||
AccionFileCmp_DateRightToLeft,
|
||||
AccionFileCmp_MakeRightDirectory,
|
||||
AccionFileCmp_MakeLeftDirectory
|
||||
} AccionFileCmp;
|
||||
ActionFileCmp_Nothing,
|
||||
ActionFileCmp_LeftToRight,
|
||||
ActionFileCmp_RightToLeft,
|
||||
ActionFileCmp_DeleteLeft,
|
||||
ActionFileCmp_DeleteRight,
|
||||
ActionFileCmp_DateLeftToRight,
|
||||
ActionFileCmp_DateRightToLeft,
|
||||
ActionFileCmp_MakeRightDirectory,
|
||||
ActionFileCmp_MakeLeftDirectory
|
||||
} ActionFileCmp;
|
||||
|
||||
typedef struct SAccionFileNode {
|
||||
AccionFileCmp action;
|
||||
typedef struct SActionFileNode {
|
||||
ActionFileCmp action;
|
||||
FileNode *left;
|
||||
FileNode *right;
|
||||
struct SAccionFileNode *next;
|
||||
} AccionFileNode;
|
||||
struct SActionFileNode *next;
|
||||
} ActionFileNode;
|
||||
|
||||
AccionFileNode *AccionFileNode_Create();
|
||||
void AccionFileNode_Destroy(AccionFileNode *actionFileNode);
|
||||
AccionFileNode *AccionFileNode_CreateNormal(FileNode *fileNodeLeft,
|
||||
ActionFileNode *ActionFileNode_Create();
|
||||
void AccionFileNode_Destroy(ActionFileNode *actionFileNode);
|
||||
ActionFileNode *ActionFileNode_CreateNormal(FileNode *fileNodeLeft,
|
||||
FileNode *fileNodeRight);
|
||||
|
||||
AccionFileNode *AccionFileNode_BuildSync(FileNode *fileNodeLeft,
|
||||
ActionFileNode *ActionFileNode_BuildSync(FileNode *fileNodeLeft,
|
||||
FileNode *fileNodeRight);
|
||||
AccionFileNode *AccionFileNode_BuildCopy(FileNode *fileNodeLeft,
|
||||
ActionFileNode *ActionFileNode_BuildCopy(FileNode *fileNodeLeft,
|
||||
FileNode *fileNodeRight);
|
||||
|
||||
typedef struct SActionQueueStatistics {
|
||||
@@ -45,12 +45,12 @@ typedef struct SActionQueueStatistics {
|
||||
long long deleteRight;
|
||||
} ActionQueueStatistics;
|
||||
|
||||
void AccionFileNode_Statistics(AccionFileNode *actionFileNode,
|
||||
void ActionFileNode_Statistics(ActionFileNode *actionFileNode,
|
||||
ActionQueueStatistics *statistics);
|
||||
|
||||
void AccionFileNode_Print(AccionFileNode *actionFileNode);
|
||||
void ActionFileNode_Print(ActionFileNode *actionFileNode);
|
||||
|
||||
void AccionFileNode_RunList(AccionFileNode *actionFileNode, char *pathLeft,
|
||||
void ActionFileNode_RunList(ActionFileNode *actionFileNode, char *pathLeft,
|
||||
char *pathRight);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -110,7 +110,8 @@ void File_GetName(char *path, char *name) {
|
||||
if (path[i] == '/' || path[i] == '\\') {
|
||||
i++;
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
@@ -266,11 +267,10 @@ void File_IterateDir(char *path,
|
||||
if (handle == -1)
|
||||
return;
|
||||
|
||||
// Recorrer el directorio
|
||||
// Iterate directory
|
||||
do {
|
||||
if (strcmp(fileinfo.name, ".") && strcmp(fileinfo.name, "..")) {
|
||||
// A partir de aqui hay un fichero
|
||||
// (o directorio)
|
||||
// Each item
|
||||
snprintf(f_path, 512, "%s/%s", path, fileinfo.name);
|
||||
fin = func(f_path, fileinfo.name, data);
|
||||
}
|
||||
@@ -293,14 +293,13 @@ void File_IterateDir(char *path,
|
||||
if (directorio == NULL)
|
||||
return;
|
||||
|
||||
// Recorrer el directorio
|
||||
// Iterate directory
|
||||
do {
|
||||
entidad_dir = readdir(directorio);
|
||||
if (entidad_dir != NULL) {
|
||||
if (strcmp(entidad_dir->d_name, ".")
|
||||
&& strcmp(entidad_dir->d_name, "..")) {
|
||||
// A partir de aqui hay un fichero
|
||||
// (o directorio)
|
||||
// Each item
|
||||
snprintff(f_path, MaxPath, "%s/%s", path, entidad_dir->d_name);
|
||||
fin = func(f_path, entidad_dir->d_name, data);
|
||||
}
|
||||
@@ -329,7 +328,7 @@ void File_DeleteDirectory(char *path) {
|
||||
#define MaxBuffer 16384
|
||||
int File_Copy(const char *pathOrig, const char *pathDest) {
|
||||
FILE *fOrig, *fDest;
|
||||
char buffer[MaxBuffer];
|
||||
char *buffer = NULL;
|
||||
int readLen = 0;
|
||||
int writeLen = 0;
|
||||
int ok = 0;
|
||||
@@ -341,14 +340,20 @@ int File_Copy(const char *pathOrig, const char *pathDest) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
buffer = malloc(sizeof(char)*MaxBuffer);
|
||||
if (buffer == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
do {
|
||||
readLen = fread(&buffer, 1, MaxBuffer, fOrig);
|
||||
readLen = fread(buffer, 1, MaxBuffer, fOrig);
|
||||
if (readLen > 0) {
|
||||
writeLen = fwrite(&buffer, 1, readLen, fDest);
|
||||
if (writeLen != readLen) {
|
||||
// Error
|
||||
fclose(fOrig);
|
||||
fclose(fDest);
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -360,5 +365,6 @@ int File_Copy(const char *pathOrig, const char *pathDest) {
|
||||
|
||||
fclose(fOrig);
|
||||
fclose(fDest);
|
||||
free(buffer);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ void FileTime_Print(FileTime t);
|
||||
///////////////////////////////////////////////
|
||||
// File
|
||||
#define MaxPath 4096
|
||||
#define MaxFilename 512
|
||||
#define MaxFilename 2048
|
||||
|
||||
void File_GetName(char *path, char *name);
|
||||
|
||||
@@ -23,9 +23,9 @@ int File_IsDirectory(char *path);
|
||||
|
||||
int File_IsFile(char *path);
|
||||
|
||||
long long File_GetSize(char *ficheros);
|
||||
long long File_GetSize(char *fileName);
|
||||
|
||||
void File_GetSizeAndTime(char *ficheros, long long *size, FileTime *time);
|
||||
void File_GetSizeAndTime(char *fileName, long long *size, FileTime *time);
|
||||
|
||||
int File_MakeDirectory(char *path);
|
||||
|
||||
|
||||
100
src/main.c
100
src/main.c
@@ -49,8 +49,9 @@ int main(int argc, char *argv[]) {
|
||||
FileNode_PrintNode(fileNode);
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(argv[1], "scan") && argc == 4) {
|
||||
// Scanear informacion de directorio y guardar arbol
|
||||
}
|
||||
else if (!strcmp(argv[1], "scan") && argc == 4) {
|
||||
// Scan directory information tree and save
|
||||
long long tScan = Time_GetTime();
|
||||
FileNode *fileNode;
|
||||
printff("Building FileNode..\n");
|
||||
@@ -58,8 +59,9 @@ int main(int argc, char *argv[]) {
|
||||
tScan = Time_GetTime() - tScan;
|
||||
printff("tScan: %9lldus\n", tScan);
|
||||
FileNode_Save(fileNode, argv[3]);
|
||||
} else if (!strcmp(argv[1], "rescan") && argc == 4) {
|
||||
// Scanear informacion de directorio y guardar arbol
|
||||
}
|
||||
else if (!strcmp(argv[1], "rescan") && argc == 4) {
|
||||
// Scan directory information and save tree
|
||||
FileNode *fileNode;
|
||||
printff("Loading FileNode..\n");
|
||||
fileNode = FileNode_Load(argv[3]);
|
||||
@@ -70,7 +72,8 @@ int main(int argc, char *argv[]) {
|
||||
tScan = Time_GetTime() - tScan;
|
||||
printff("tScan: %9lldus\n", tScan);
|
||||
FileNode_Save(fileNode, argv[3]);
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
printff("Building FileNode..\n");
|
||||
long long tScan = Time_GetTime();
|
||||
fileNode = FileNode_Build(argv[2]);
|
||||
@@ -78,14 +81,16 @@ int main(int argc, char *argv[]) {
|
||||
printff("tScan: %9lldus\n", tScan);
|
||||
FileNode_Save(fileNode, argv[3]);
|
||||
}
|
||||
} else if (!strcmp(argv[1], "read") && argc == 3) {
|
||||
// Leer informacion de arbol
|
||||
}
|
||||
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) {
|
||||
// Leer informacion de dir
|
||||
}
|
||||
else if (!strcmp(argv[1], "dir") && argc == 3) {
|
||||
// Read directory information tree
|
||||
char *path = argv[2];
|
||||
FileNode *fileNode;
|
||||
|
||||
@@ -93,28 +98,37 @@ int main(int argc, char *argv[]) {
|
||||
if (fileNode) {
|
||||
FileNode_Print(fileNode);
|
||||
}
|
||||
} 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]);
|
||||
}
|
||||
|
||||
@@ -125,7 +139,7 @@ FileNode *CheckDir(char *path, int recheck) {
|
||||
char dirNodesFile[MaxPath];
|
||||
FileNode *fileNode;
|
||||
|
||||
// Comprobar directorio
|
||||
// Check directory
|
||||
snprintf(dirNodesFile, MaxPath, "%s/"FileNode_Filename, path);
|
||||
if (recheck) {
|
||||
printff("Checking Directory.. %s\n", path);
|
||||
@@ -133,13 +147,15 @@ FileNode *CheckDir(char *path, int recheck) {
|
||||
fileNode = FileNode_Load(dirNodesFile);
|
||||
if (fileNode) {
|
||||
fileNode = FileNode_Refresh(fileNode, path);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
fileNode = FileNode_Build(path);
|
||||
}
|
||||
tScan = Time_GetTime() - tScan;
|
||||
printff("tScan: %9lldus\n", tScan);
|
||||
FileNode_Save(fileNode, dirNodesFile);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
printff("Loading Directory.. %s\n", path);
|
||||
fileNode = FileNode_Load(dirNodesFile);
|
||||
if (!fileNode) {
|
||||
@@ -150,9 +166,9 @@ FileNode *CheckDir(char *path, int recheck) {
|
||||
return fileNode;
|
||||
}
|
||||
|
||||
void PrintStatistics(AccionFileNode *actionFileNode) {
|
||||
void PrintStatistics(ActionFileNode *actionFileNode) {
|
||||
ActionQueueStatistics statistics;
|
||||
AccionFileNode_Statistics(actionFileNode, &statistics);
|
||||
ActionFileNode_Statistics(actionFileNode, &statistics);
|
||||
printff("Statistics\n");
|
||||
printff(" % 12s % 12s % 12s\n", "Read", "Write", "Delete");
|
||||
printff("Left : % 12lld % 12lld % 12lld\n", statistics.readLeft,
|
||||
@@ -169,7 +185,7 @@ void PrintStatistics(AccionFileNode *actionFileNode) {
|
||||
int Sync(char *pathLeft, char *pathRight, int recheck, int dryRun) {
|
||||
FileNode *fileNodeLeft, *fileNodeRight;
|
||||
|
||||
// Comprobar y cargar directorios
|
||||
// Check and load directories
|
||||
if (!File_ExistsPath(pathLeft) || !File_IsDirectory(pathLeft)) {
|
||||
printff("Error, directory does not exist: %s\n", pathLeft);
|
||||
return 0;
|
||||
@@ -187,21 +203,22 @@ int Sync(char *pathLeft, char *pathRight, int recheck, int dryRun) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Construir acciones
|
||||
// Build actions
|
||||
long long tBuild = Time_GetTime();
|
||||
printff("Building action list.. \n");
|
||||
AccionFileNode *actionFileNode = NULL;
|
||||
actionFileNode = AccionFileNode_BuildSync(fileNodeLeft, fileNodeRight);
|
||||
ActionFileNode *actionFileNode = NULL;
|
||||
actionFileNode = ActionFileNode_BuildSync(fileNodeLeft, fileNodeRight);
|
||||
tBuild = Time_GetTime() - tBuild;
|
||||
printff("tBuild: %9lldus\n", tBuild);
|
||||
|
||||
if (dryRun) {
|
||||
// Mostrar lista de acciones
|
||||
AccionFileNode_Print(actionFileNode);
|
||||
// Show action list
|
||||
ActionFileNode_Print(actionFileNode);
|
||||
PrintStatistics(actionFileNode);
|
||||
} else {
|
||||
// Ejecutar lista de acciones
|
||||
AccionFileNode_RunList(actionFileNode, pathLeft, pathRight);
|
||||
}
|
||||
else {
|
||||
// Run action list
|
||||
ActionFileNode_RunList(actionFileNode, pathLeft, pathRight);
|
||||
}
|
||||
|
||||
return (1);
|
||||
@@ -210,7 +227,7 @@ int Sync(char *pathLeft, char *pathRight, int recheck, int dryRun) {
|
||||
int Copy(char *pathLeft, char *pathRight, int reCheck, int dryRun) {
|
||||
FileNode *fileNodeLeft, *fileNodeRight;
|
||||
|
||||
// Comprobar y cargar directorios
|
||||
// Check and load directories
|
||||
if (!File_ExistsPath(pathLeft) || !File_IsDirectory(pathLeft)) {
|
||||
printff("Error, directory does not exist: %s\n", pathLeft);
|
||||
return 0;
|
||||
@@ -228,21 +245,22 @@ int Copy(char *pathLeft, char *pathRight, int reCheck, int dryRun) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Construir acciones
|
||||
// Build actions
|
||||
long long tBuild = Time_GetTime();
|
||||
printff("Building action list.. \n");
|
||||
AccionFileNode *actionFileNode = NULL;
|
||||
actionFileNode = AccionFileNode_BuildCopy(fileNodeLeft, fileNodeRight);
|
||||
ActionFileNode *actionFileNode = NULL;
|
||||
actionFileNode = ActionFileNode_BuildCopy(fileNodeLeft, fileNodeRight);
|
||||
tBuild = Time_GetTime() - tBuild;
|
||||
printff("tBuild: %9lldus\n", tBuild);
|
||||
|
||||
if (dryRun) {
|
||||
// Mostrar lista de acciones
|
||||
AccionFileNode_Print(actionFileNode);
|
||||
// Show action list
|
||||
ActionFileNode_Print(actionFileNode);
|
||||
PrintStatistics(actionFileNode);
|
||||
} else {
|
||||
// Ejecutar lista de acciones
|
||||
AccionFileNode_RunList(actionFileNode, pathLeft, pathRight);
|
||||
}
|
||||
else {
|
||||
// Run action list
|
||||
ActionFileNode_RunList(actionFileNode, pathLeft, pathRight);
|
||||
}
|
||||
|
||||
return (1);
|
||||
|
||||
29
src/util.c
29
src/util.c
@@ -9,22 +9,20 @@ char *String_Copy(char *str) {
|
||||
int len;
|
||||
len = strlen(str);
|
||||
strnew = malloc(len + 1);
|
||||
if (strnew != NULL) {
|
||||
strcpy(strnew, str);
|
||||
}
|
||||
return (strnew);
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////
|
||||
// Time_GetTime
|
||||
//
|
||||
// Gets the current time in usecs.
|
||||
/////////////////////////////
|
||||
// Time_Pause
|
||||
//
|
||||
// Pauses the execution for t usecs.
|
||||
#if WIN32
|
||||
#include <windows.h>
|
||||
// WIN32
|
||||
/////////////////////////////
|
||||
// Time_GetTime
|
||||
//
|
||||
// Gets the current time in usecs. WIN32 version.
|
||||
long long Time_GetTime(){
|
||||
LARGE_INTEGER freq;
|
||||
LARGE_INTEGER tim;
|
||||
@@ -35,6 +33,11 @@ long long Time_GetTime(){
|
||||
microt=(tim.QuadPart*1000000)/freq.QuadPart;
|
||||
return(microt);
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// Time_Pause
|
||||
//
|
||||
// Pauses the execution for t usecs. WIN32 version.
|
||||
void Time_Pause(int pausa){
|
||||
long long tend,t,diff;
|
||||
|
||||
@@ -51,7 +54,10 @@ void Time_Pause(int pausa){
|
||||
}while(tend>=t);
|
||||
}
|
||||
#else
|
||||
// UNIX
|
||||
/////////////////////////////
|
||||
// Time_GetTime
|
||||
//
|
||||
// Gets the current time in usecs. UNIX version.
|
||||
long long Time_GetTime(){
|
||||
struct timeval t;
|
||||
long long usecs;
|
||||
@@ -59,6 +65,11 @@ long long Time_GetTime(){
|
||||
usecs=(t.tv_sec*1000000ll)+(t.tv_usec);
|
||||
return(usecs);
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
// Time_Pause
|
||||
//
|
||||
// Pauses the execution for t usecs. UNIX version.
|
||||
void Time_Pause(int pausa){
|
||||
struct timeval tv;
|
||||
tv.tv_sec=(long long)pausa/1000000;
|
||||
|
||||
Reference in New Issue
Block a user