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