Variable and function renaming
This commit is contained in:
34
crc.c
34
crc.c
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned long CRCTable[256];
|
||||
int CRCTable_initialized = 0;
|
||||
unsigned long _crcTable[256];
|
||||
int _crcTableInitialized = 0;
|
||||
|
||||
#define CRC32_POLYNOMIAL 0xEDB88320L
|
||||
|
||||
@@ -10,10 +10,10 @@ void CRCTable_Init() {
|
||||
int j;
|
||||
unsigned long crc;
|
||||
|
||||
if (CRCTable_initialized) {
|
||||
if (_crcTableInitialized) {
|
||||
return;
|
||||
}
|
||||
CRCTable_initialized = 1;
|
||||
_crcTableInitialized = 1;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
crc = i;
|
||||
@@ -23,45 +23,45 @@ void CRCTable_Init() {
|
||||
else
|
||||
crc >>= 1;
|
||||
}
|
||||
CRCTable[i] = crc;
|
||||
_crcTable[i] = crc;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long CRC_Buffer(unsigned char *buffer, int len, unsigned long crc) {
|
||||
unsigned long CRC_BufferInternal(unsigned char *buffer, int len,
|
||||
unsigned long crc) {
|
||||
unsigned char *p;
|
||||
unsigned long temp1;
|
||||
unsigned long temp2;
|
||||
|
||||
// Calcular CRC del buffer
|
||||
p = (unsigned char*) buffer;
|
||||
while (len-- != 0) {
|
||||
temp1 = (crc >> 8) & 0x00FFFFFFL;
|
||||
temp2 = CRCTable[((int) crc ^ *p++) & 0xff];
|
||||
crc = temp1 ^ temp2;
|
||||
unsigned long termA = (crc >> 8) & 0x00FFFFFFL;
|
||||
unsigned long termB = _crcTable[((int) crc ^ *p++) & 0xff];
|
||||
crc = termA ^ termB;
|
||||
}
|
||||
|
||||
return (crc);
|
||||
}
|
||||
|
||||
unsigned long CRC_Buffer(unsigned char *buffer, int len, unsigned long crc) {
|
||||
CRCTable_Init();
|
||||
return (CRC_BufferInternal(buffer, len, crc));
|
||||
}
|
||||
|
||||
unsigned long CRC_File(FILE *file) {
|
||||
unsigned long crc;
|
||||
int count;
|
||||
unsigned char buffer[512];
|
||||
unsigned char *p;
|
||||
unsigned long temp1;
|
||||
unsigned long temp2;
|
||||
|
||||
CRCTable_Init();
|
||||
|
||||
crc = 0xFFFFFFFFL;
|
||||
for (;;) {
|
||||
// Llenar el buffer
|
||||
count = fread(buffer, 1, 512, file);
|
||||
int count = fread(buffer, 1, 512, file);
|
||||
if (count == 0)
|
||||
break;
|
||||
|
||||
// Calcular CRC del buffer
|
||||
crc = CRC_Buffer(buffer, count, crc);
|
||||
crc = CRC_BufferInternal(buffer, count, crc);
|
||||
}
|
||||
return (crc ^= 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
404
filenode.c
404
filenode.c
@@ -9,84 +9,84 @@
|
||||
|
||||
FileNode *_free_filenode = NULL;
|
||||
int _n_filenode = 0;
|
||||
#define FileNode_Tocho 1024
|
||||
FileNode *FileNode_New() {
|
||||
FileNode *fn;
|
||||
#define FileNode_Block 1024
|
||||
FileNode *FileNode_Create() {
|
||||
FileNode *fileNode;
|
||||
|
||||
if (_free_filenode == NULL ) {
|
||||
FileNode *nodos;
|
||||
int i;
|
||||
// Reservar un tocho
|
||||
nodos = malloc(sizeof(FileNode) * FileNode_Tocho);
|
||||
for (i = 0; i < FileNode_Tocho - 1; i++) {
|
||||
nodos[i].sig = &nodos[i + 1];
|
||||
nodos = malloc(sizeof(FileNode) * FileNode_Block);
|
||||
for (i = 0; i < FileNode_Block - 1; i++) {
|
||||
nodos[i].next = &nodos[i + 1];
|
||||
}
|
||||
nodos[FileNode_Tocho - 1].sig = NULL;
|
||||
nodos[FileNode_Block - 1].next = NULL;
|
||||
_free_filenode = &nodos[0];
|
||||
}
|
||||
|
||||
// Obtener el primero libre
|
||||
fn = _free_filenode;
|
||||
_free_filenode = fn->sig;
|
||||
fileNode = _free_filenode;
|
||||
_free_filenode = fileNode->next;
|
||||
_n_filenode++;
|
||||
|
||||
// Iniciar
|
||||
fn->name[0] = 0;
|
||||
fn->flags = 0;
|
||||
fn->estado = EstadoFichero_Nada;
|
||||
fn->size = 0;
|
||||
fn->crc = 0;
|
||||
fn->ft = 0;
|
||||
fn->child = NULL;
|
||||
fn->n_childs = 0;
|
||||
fn->sig = NULL;
|
||||
fn->padre = NULL;
|
||||
fileNode->name[0] = 0;
|
||||
fileNode->flags = 0;
|
||||
fileNode->estado = FileStatus_None;
|
||||
fileNode->size = 0;
|
||||
fileNode->crc = 0;
|
||||
fileNode->fileTime = 0;
|
||||
fileNode->child = NULL;
|
||||
fileNode->childCount = 0;
|
||||
fileNode->next = NULL;
|
||||
fileNode->parent = NULL;
|
||||
|
||||
return (fn);
|
||||
return (fileNode);
|
||||
}
|
||||
|
||||
void FileNode_Delete(FileNode *fn) {
|
||||
fn->sig = _free_filenode;
|
||||
fn->next = _free_filenode;
|
||||
_free_filenode = fn;
|
||||
_n_filenode--;
|
||||
}
|
||||
|
||||
void FileNode_AddChild(FileNode *file, FileNode *file2) {
|
||||
if (!file2 || !file)
|
||||
void FileNode_AddChild(FileNode *fileNode, FileNode *file2) {
|
||||
if (!file2 || !fileNode)
|
||||
return;
|
||||
file2->sig = file->child;
|
||||
file->child = file2;
|
||||
file->n_childs++;
|
||||
file2->padre = file;
|
||||
file2->next = fileNode->child;
|
||||
fileNode->child = file2;
|
||||
fileNode->childCount++;
|
||||
file2->parent = fileNode;
|
||||
}
|
||||
|
||||
void FileNode_SetEstadoRec(FileNode *file, EstadoFichero estado) {
|
||||
void FileNode_SetEstadoRec(FileNode *fileNode, FileStatus estado) {
|
||||
FileNode *fn_child;
|
||||
file->estado = estado;
|
||||
fn_child = file->child;
|
||||
fileNode->estado = estado;
|
||||
fn_child = fileNode->child;
|
||||
while (fn_child != NULL ) {
|
||||
FileNode_SetEstadoRec(fn_child, estado);
|
||||
fn_child = fn_child->sig;
|
||||
fn_child = fn_child->next;
|
||||
}
|
||||
}
|
||||
|
||||
void FileNode_GetPath_Rec(FileNode *fn, char **pathnode) {
|
||||
if (fn->padre) {
|
||||
pathnode[0] = fn->padre->name;
|
||||
FileNode_GetPath_Rec(fn->padre, pathnode + 1);
|
||||
void FileNode_GetPath_Rec(FileNode *fileNode, char **pathnode) {
|
||||
if (fileNode->parent) {
|
||||
pathnode[0] = fileNode->parent->name;
|
||||
FileNode_GetPath_Rec(fileNode->parent, pathnode + 1);
|
||||
} else {
|
||||
pathnode[0] = NULL;
|
||||
}
|
||||
}
|
||||
char temppath[MaxPath];
|
||||
char *FileNode_GetPath(FileNode *fn, char *path) {
|
||||
char *FileNode_GetPath(FileNode *fileNode, char *path) {
|
||||
char *pathnodes[128];
|
||||
int levels, i;
|
||||
char *pathptr = temppath;
|
||||
if (path)
|
||||
pathptr = path;
|
||||
|
||||
FileNode_GetPath_Rec(fn, pathnodes);
|
||||
FileNode_GetPath_Rec(fileNode, pathnodes);
|
||||
levels = 0;
|
||||
while (pathnodes[levels]) {
|
||||
levels++;
|
||||
@@ -96,17 +96,17 @@ char *FileNode_GetPath(FileNode *fn, char *path) {
|
||||
strcat(pathptr, pathnodes[i]);
|
||||
strcat(pathptr, "/");
|
||||
}
|
||||
strcat(pathptr, fn->name);
|
||||
strcat(pathptr, fileNode->name);
|
||||
return temppath;
|
||||
}
|
||||
char *FileNode_GetFullPath(FileNode *fn, char *basePath, char *path) {
|
||||
char *FileNode_GetFullPath(FileNode *fileNode, char *basePath, char *path) {
|
||||
char *pathnodes[128];
|
||||
int levels, i;
|
||||
char *pathptr = temppath;
|
||||
if (path)
|
||||
pathptr = path;
|
||||
|
||||
FileNode_GetPath_Rec(fn, pathnodes);
|
||||
FileNode_GetPath_Rec(fileNode, pathnodes);
|
||||
levels = 0;
|
||||
while (pathnodes[levels]) {
|
||||
levels++;
|
||||
@@ -117,80 +117,80 @@ char *FileNode_GetFullPath(FileNode *fn, char *basePath, char *path) {
|
||||
strcat(pathptr, pathnodes[i]);
|
||||
strcat(pathptr, "/");
|
||||
}
|
||||
strcat(pathptr, fn->name);
|
||||
strcat(pathptr, fileNode->name);
|
||||
return temppath;
|
||||
}
|
||||
|
||||
void FileNode_GetTamanho(FileNode *fn, char *file) {
|
||||
fn->flags |= FileFlag_TieneTamanho;
|
||||
fn->size = File_TamanhoFichero(file);
|
||||
void FileNode_GetSize(FileNode *fileNode, char *filePath) {
|
||||
fileNode->flags |= FileFlag_HasSize;
|
||||
fileNode->size = File_GetSize(filePath);
|
||||
}
|
||||
|
||||
void FileNode_GetFecha(FileNode *fn, char *file) {
|
||||
fn->flags |= FileFlag_TieneFecha;
|
||||
fn->ft = FileTime_Get(file);
|
||||
void FileNode_GetFecha(FileNode *fileNode, char *filePath) {
|
||||
fileNode->flags |= FileFlag_HastTime;
|
||||
fileNode->fileTime = FileTime_Get(filePath);
|
||||
}
|
||||
|
||||
void FileNode_GetCRC(FileNode *fn, char *file) {
|
||||
FILE *f;
|
||||
f = fopen(file, "rb");
|
||||
if (!f) {
|
||||
void FileNode_GetCRC(FileNode *fileNode, char *filePath) {
|
||||
FILE *file;
|
||||
file = fopen(filePath, "rb");
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
fn->flags |= FileFlag_TieneCRC;
|
||||
fn->crc = CRC_File(f);
|
||||
fclose(f);
|
||||
fileNode->flags |= FileFlag_HasCRC;
|
||||
fileNode->crc = CRC_File(file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
void FileNode_SaveNode(FileNode *fn, FILE *file) {
|
||||
void FileNode_SaveNode(FileNode *fileNode, FILE *file) {
|
||||
short name_len;
|
||||
|
||||
// Escribir nombre
|
||||
name_len = strlen(fn->name);
|
||||
name_len = strlen(fileNode->name);
|
||||
fwrite((void *) &name_len, sizeof(name_len), 1, file);
|
||||
fputs(fn->name, file);
|
||||
fputs(fileNode->name, file);
|
||||
|
||||
// Escribir flags
|
||||
fwrite((void *) &fn->flags, sizeof(fn->flags), 1, file);
|
||||
fwrite((void *) &fileNode->flags, sizeof(fileNode->flags), 1, file);
|
||||
|
||||
// Escribir estado
|
||||
fputc((char) fn->estado, file);
|
||||
fputc((char) fileNode->estado, file);
|
||||
|
||||
// Escribir tamanho
|
||||
if (fn->flags & FileFlag_TieneTamanho) {
|
||||
fwrite((void *) &fn->size, sizeof(fn->size), 1, file);
|
||||
if (fileNode->flags & FileFlag_HasSize) {
|
||||
fwrite((void *) &fileNode->size, sizeof(fileNode->size), 1, file);
|
||||
}
|
||||
|
||||
// Escribir fecha
|
||||
if (fn->flags & FileFlag_TieneFecha) {
|
||||
fwrite((void *) &fn->ft, sizeof(fn->ft), 1, file);
|
||||
if (fileNode->flags & FileFlag_HastTime) {
|
||||
fwrite((void *) &fileNode->fileTime, sizeof(fileNode->fileTime), 1, file);
|
||||
}
|
||||
|
||||
// Escribir CRC
|
||||
if (fn->flags & FileFlag_TieneCRC) {
|
||||
fwrite((void *) &fn->crc, sizeof(fn->crc), 1, file);
|
||||
if (fileNode->flags & FileFlag_HasCRC) {
|
||||
fwrite((void *) &fileNode->crc, sizeof(fileNode->crc), 1, file);
|
||||
}
|
||||
|
||||
// Escribir ficheros del directorio
|
||||
if (fn->flags & FileFlag_Directorio) {
|
||||
FileNode *fnc;
|
||||
fwrite((void *) &fn->n_childs, sizeof(fn->n_childs), 1, file);
|
||||
fnc = fn->child;
|
||||
while (fnc) {
|
||||
FileNode_SaveNode(fnc, file);
|
||||
fnc = fnc->sig;
|
||||
if (fileNode->flags & FileFlag_Directory) {
|
||||
FileNode *fileNodeChild;
|
||||
fwrite((void *) &fileNode->childCount, sizeof(fileNode->childCount), 1, file);
|
||||
fileNodeChild = fileNode->child;
|
||||
while (fileNodeChild) {
|
||||
FileNode_SaveNode(fileNodeChild, file);
|
||||
fileNodeChild = fileNodeChild->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FileNode_Save(FileNode *fn, char *fichero) {
|
||||
void FileNode_Save(FileNode *fileNode, char *filePath) {
|
||||
FILE *file;
|
||||
char marca[5];
|
||||
int version;
|
||||
|
||||
if (!fn)
|
||||
if (!fileNode)
|
||||
return;
|
||||
file = fopen(fichero, "wb+");
|
||||
file = fopen(filePath, "wb+");
|
||||
if (!file)
|
||||
return;
|
||||
|
||||
@@ -200,76 +200,76 @@ void FileNode_Save(FileNode *fn, char *fichero) {
|
||||
version = FileNode_Version;
|
||||
fwrite((void *) &version, sizeof(int), 1, file);
|
||||
|
||||
FileNode_SaveNode(fn, file);
|
||||
FileNode_SaveNode(fileNode, file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
FileNode *FileNode_LoadNode(FILE *file) {
|
||||
short name_len;
|
||||
FileNode *fn;
|
||||
short nameLen;
|
||||
FileNode *fileNode;
|
||||
int i;
|
||||
|
||||
fn = FileNode_New();
|
||||
fileNode = FileNode_Create();
|
||||
|
||||
// Leer el nombre
|
||||
fread((void *) &name_len, sizeof(name_len), 1, file);
|
||||
fread((void *) fn->name, sizeof(char), name_len, file);
|
||||
fn->name[name_len] = 0;
|
||||
fread((void *) &nameLen, sizeof(nameLen), 1, file);
|
||||
fread((void *) fileNode->name, sizeof(char), nameLen, file);
|
||||
fileNode->name[nameLen] = 0;
|
||||
|
||||
// Leer vanderas
|
||||
fread((void *) &fn->flags, sizeof(fn->flags), 1, file);
|
||||
fread((void *) &fileNode->flags, sizeof(fileNode->flags), 1, file);
|
||||
|
||||
// Leer estado
|
||||
fn->estado = fgetc(file);
|
||||
fileNode->estado = fgetc(file);
|
||||
|
||||
// Leer tamanho
|
||||
if (fn->flags & FileFlag_TieneTamanho) {
|
||||
fread((void *) &fn->size, sizeof(fn->size), 1, file);
|
||||
if (fileNode->flags & FileFlag_HasSize) {
|
||||
fread((void *) &fileNode->size, sizeof(fileNode->size), 1, file);
|
||||
}
|
||||
|
||||
// Leer fecha
|
||||
if (fn->flags & FileFlag_TieneFecha) {
|
||||
fread((void *) &fn->ft, sizeof(fn->ft), 1, file);
|
||||
if (fileNode->flags & FileFlag_HastTime) {
|
||||
fread((void *) &fileNode->fileTime, sizeof(fileNode->fileTime), 1, file);
|
||||
}
|
||||
|
||||
// Leer CRC
|
||||
if (fn->flags & FileFlag_TieneCRC) {
|
||||
fread((void *) &fn->crc, sizeof(fn->crc), 1, file);
|
||||
if (fileNode->flags & FileFlag_HasCRC) {
|
||||
fread((void *) &fileNode->crc, sizeof(fileNode->crc), 1, file);
|
||||
}
|
||||
|
||||
// Leer ficheros del directorio
|
||||
if (fn->flags & FileFlag_Directorio) {
|
||||
FileNode *fnca = NULL, *fnc;
|
||||
fread((void *) &fn->n_childs, sizeof(fn->n_childs), 1, file);
|
||||
for (i = 0; i < fn->n_childs; i++) {
|
||||
fnc = FileNode_LoadNode(file);
|
||||
fnc->padre = fn;
|
||||
if (!fnca) {
|
||||
fn->child = fnc;
|
||||
if (fileNode->flags & FileFlag_Directory) {
|
||||
FileNode *fileNodeChildAux = NULL, *fileNodeChild;
|
||||
fread((void *) &fileNode->childCount, sizeof(fileNode->childCount), 1, file);
|
||||
for (i = 0; i < fileNode->childCount; i++) {
|
||||
fileNodeChild = FileNode_LoadNode(file);
|
||||
fileNodeChild->parent = fileNode;
|
||||
if (!fileNodeChildAux) {
|
||||
fileNode->child = fileNodeChild;
|
||||
} else {
|
||||
fnca->sig = fnc;
|
||||
fileNodeChildAux->next = fileNodeChild;
|
||||
}
|
||||
fnca = fnc;
|
||||
fileNodeChildAux = fileNodeChild;
|
||||
}
|
||||
}
|
||||
|
||||
return (fn);
|
||||
return (fileNode);
|
||||
}
|
||||
|
||||
FileNode *FileNode_Load(char *fichero) {
|
||||
FileNode *FileNode_Load(char *filePath) {
|
||||
FILE *file;
|
||||
FileNode *fn;
|
||||
char marca[5];
|
||||
FileNode *fileNode;
|
||||
char mark[5];
|
||||
int version;
|
||||
|
||||
file = fopen(fichero, "rb");
|
||||
file = fopen(filePath, "rb");
|
||||
if (!file)
|
||||
return (NULL );
|
||||
|
||||
// Leer marca y version
|
||||
fread((void *) marca, sizeof(char), 4, file);
|
||||
marca[4] = 0;
|
||||
if (strcmp(marca, "sYnC")) {
|
||||
fread((void *) mark, sizeof(char), 4, file);
|
||||
mark[4] = 0;
|
||||
if (strcmp(mark, "sYnC")) {
|
||||
// Marca incorrecta
|
||||
fclose(file);
|
||||
return (NULL );
|
||||
@@ -281,27 +281,27 @@ FileNode *FileNode_Load(char *fichero) {
|
||||
return (NULL );
|
||||
}
|
||||
|
||||
fn = FileNode_LoadNode(file);
|
||||
fileNode = FileNode_LoadNode(file);
|
||||
fclose(file);
|
||||
|
||||
return (fn);
|
||||
return (fileNode);
|
||||
}
|
||||
|
||||
void FileNode_PrintNode(FileNode *fn) {
|
||||
printf(FileNode_GetPath(fn, NULL ));
|
||||
if (fn->flags & FileFlag_Normal) {
|
||||
void FileNode_PrintNode(FileNode *fileNode) {
|
||||
printf(FileNode_GetPath(fileNode, NULL ));
|
||||
if (fileNode->flags & FileFlag_Normal) {
|
||||
printf(" File");
|
||||
} else {
|
||||
printf(" Dir");
|
||||
}
|
||||
printf(" %d", fn->estado);
|
||||
if (fn->estado == EstadoFichero_Nuevo) {
|
||||
printf(" %d", fileNode->estado);
|
||||
if (fileNode->estado == FileStatus_New) {
|
||||
printf(" Nuevo");
|
||||
}
|
||||
if (fn->estado == EstadoFichero_Modificado) {
|
||||
if (fileNode->estado == FileStatus_Modified) {
|
||||
printf(" Modificado");
|
||||
}
|
||||
if (fn->estado == EstadoFichero_Borrado) {
|
||||
if (fileNode->estado == FileStatus_Deleted) {
|
||||
printf(" Borrado!!!");
|
||||
}
|
||||
printf("\n");
|
||||
@@ -324,29 +324,29 @@ void FileNode_PrintNode(FileNode *fn) {
|
||||
*/
|
||||
}
|
||||
|
||||
void FileNode_Print(FileNode *fn) {
|
||||
FileNode *fnAux = fn;
|
||||
void FileNode_Print(FileNode *fileNode) {
|
||||
FileNode *fileNodeAux = fileNode;
|
||||
int end = 0;
|
||||
|
||||
while (fnAux != NULL && !end) {
|
||||
while (fileNodeAux != NULL && !end) {
|
||||
|
||||
if (fnAux->padre != NULL ) {
|
||||
FileNode_PrintNode(fnAux);
|
||||
if (fileNodeAux->parent != NULL ) {
|
||||
FileNode_PrintNode(fileNodeAux);
|
||||
}
|
||||
|
||||
if (fnAux->child) {
|
||||
fnAux = fnAux->child;
|
||||
if (fileNodeAux->child) {
|
||||
fileNodeAux = fileNodeAux->child;
|
||||
} else {
|
||||
while (fnAux->sig == NULL ) {
|
||||
fnAux = fnAux->padre;
|
||||
if (fnAux == fn || fnAux == NULL ) {
|
||||
while (fileNodeAux->next == NULL ) {
|
||||
fileNodeAux = fileNodeAux->parent;
|
||||
if (fileNodeAux == fileNode || fileNodeAux == NULL ) {
|
||||
printf("End\n");
|
||||
end = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!end) {
|
||||
fnAux = fnAux->sig;
|
||||
fileNodeAux = fileNodeAux->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -355,154 +355,154 @@ void FileNode_Print(FileNode *fn) {
|
||||
int FileNode_Build_Iterate(char *path, char *name, void *d);
|
||||
|
||||
FileNode *FileNode_Build(char *path) {
|
||||
FileNode *file;
|
||||
FileNode *fileNode;
|
||||
|
||||
if (!File_ExistePath(path))
|
||||
if (!File_ExistsPath(path))
|
||||
return (NULL );
|
||||
|
||||
// Crear el nodo
|
||||
file = FileNode_New();
|
||||
File_GetName(path, file->name);
|
||||
fileNode = FileNode_Create();
|
||||
File_GetName(path, fileNode->name);
|
||||
|
||||
// Determinar si es un fichero o directorio
|
||||
if (File_EsDirectorio(path)) {
|
||||
if (File_IsDirectory(path)) {
|
||||
// Obtener datos para los directorios
|
||||
file->flags |= FileFlag_Directorio;
|
||||
FileNode_GetFecha(file, path);
|
||||
File_IterateDir(path, FileNode_Build_Iterate, file);
|
||||
fileNode->flags |= FileFlag_Directory;
|
||||
FileNode_GetFecha(fileNode, path);
|
||||
File_IterateDir(path, FileNode_Build_Iterate, fileNode);
|
||||
} else {
|
||||
// Obtener datos para los ficheros
|
||||
file->flags |= FileFlag_Normal;
|
||||
FileNode_GetTamanho(file, path);
|
||||
FileNode_GetFecha(file, path);
|
||||
fileNode->flags |= FileFlag_Normal;
|
||||
FileNode_GetSize(fileNode, path);
|
||||
FileNode_GetFecha(fileNode, path);
|
||||
}
|
||||
|
||||
return (file);
|
||||
return (fileNode);
|
||||
}
|
||||
|
||||
int FileNode_Build_Iterate(char *path, char *name, void *d) {
|
||||
FileNode *file, *fn_padre = d;
|
||||
FileNode *fileNode, *fileNodeParent = d;
|
||||
;
|
||||
|
||||
if (!strcmp(name, FileNode_Filename)) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
file = FileNode_Build(path);
|
||||
FileNode_AddChild(fn_padre, file);
|
||||
fileNode = FileNode_Build(path);
|
||||
FileNode_AddChild(fileNodeParent, fileNode);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int FileNode_Refresh_Iterate(char *path, char *name, void *d);
|
||||
|
||||
FileNode *FileNode_Refresh(FileNode *fn, char *path) {
|
||||
if (!File_ExistePath(path)) {
|
||||
FileNode *FileNode_Refresh(FileNode *fileNode, char *filePath) {
|
||||
if (!File_ExistsPath(filePath)) {
|
||||
// El fichero/directorio ha sido borrado
|
||||
if (!fn) {
|
||||
fn = FileNode_New();
|
||||
File_GetName(path, fn->name);
|
||||
if (!fileNode) {
|
||||
fileNode = FileNode_Create();
|
||||
File_GetName(filePath, fileNode->name);
|
||||
}
|
||||
FileNode_SetEstadoRec(fn, EstadoFichero_Borrado);
|
||||
return (fn);
|
||||
FileNode_SetEstadoRec(fileNode, FileStatus_Deleted);
|
||||
return (fileNode);
|
||||
}
|
||||
if (!fn) {
|
||||
if (!fileNode) {
|
||||
// El fichero ha sido creado
|
||||
fn = FileNode_Build(path);
|
||||
FileNode_SetEstadoRec(fn, EstadoFichero_Nuevo);
|
||||
fileNode = FileNode_Build(filePath);
|
||||
FileNode_SetEstadoRec(fileNode, FileStatus_New);
|
||||
} else {
|
||||
// Comprobar si ha sido modificado
|
||||
FileTime ft;
|
||||
FileTime fileTime;
|
||||
long long size;
|
||||
int crc;
|
||||
|
||||
// Marcar normal
|
||||
fn->estado = EstadoFichero_Nada;
|
||||
fn->flags &= ~FileFlag_MarcaRevision;
|
||||
fileNode->estado = FileStatus_None;
|
||||
fileNode->flags &= ~FileFlag_MarkerForReview;
|
||||
|
||||
// Determinar si es un fichero o directorio
|
||||
if (File_EsDirectorio(path)) {
|
||||
FileNode *fn_child;
|
||||
if (File_IsDirectory(filePath)) {
|
||||
FileNode *fileNodeChild;
|
||||
|
||||
// Comparar datos de los directorios
|
||||
if (!(fn->flags & FileFlag_Directorio)) {
|
||||
fn->estado = EstadoFichero_Modificado;
|
||||
fn->flags |= FileFlag_Directorio;
|
||||
fn->flags &= ~FileFlag_Normal;
|
||||
if (!(fileNode->flags & FileFlag_Directory)) {
|
||||
fileNode->estado = FileStatus_Modified;
|
||||
fileNode->flags |= FileFlag_Directory;
|
||||
fileNode->flags &= ~FileFlag_Normal;
|
||||
}
|
||||
ft = FileTime_Get(path);
|
||||
if (ft != fn->ft) {
|
||||
fn->estado = EstadoFichero_Modificado;
|
||||
fn->ft = ft;
|
||||
fileTime = FileTime_Get(filePath);
|
||||
if (fileTime != fileNode->fileTime) {
|
||||
fileNode->estado = FileStatus_Modified;
|
||||
fileNode->fileTime = fileTime;
|
||||
}
|
||||
|
||||
// Marcar hijos para determinar cual es actualizado
|
||||
fn_child = fn->child;
|
||||
while (fn_child) {
|
||||
fn_child->flags |= FileFlag_MarcaRevision;
|
||||
fn_child = fn_child->sig;
|
||||
fileNodeChild = fileNode->child;
|
||||
while (fileNodeChild) {
|
||||
fileNodeChild->flags |= FileFlag_MarkerForReview;
|
||||
fileNodeChild = fileNodeChild->next;
|
||||
}
|
||||
|
||||
// Escanear subdirectorios
|
||||
File_IterateDir(path, FileNode_Refresh_Iterate, fn);
|
||||
File_IterateDir(filePath, FileNode_Refresh_Iterate, fileNode);
|
||||
|
||||
// Buscar que sigan marcados (borrados)
|
||||
fn_child = fn->child;
|
||||
while (fn_child) {
|
||||
if (fn_child->flags & FileFlag_MarcaRevision) {
|
||||
fn_child->flags &= ~FileFlag_MarcaRevision;
|
||||
FileNode_SetEstadoRec(fn_child, EstadoFichero_Borrado);
|
||||
fileNodeChild = fileNode->child;
|
||||
while (fileNodeChild) {
|
||||
if (fileNodeChild->flags & FileFlag_MarkerForReview) {
|
||||
fileNodeChild->flags &= ~FileFlag_MarkerForReview;
|
||||
FileNode_SetEstadoRec(fileNodeChild, FileStatus_Deleted);
|
||||
}
|
||||
fn_child = fn_child->sig;
|
||||
fileNodeChild = fileNodeChild->next;
|
||||
}
|
||||
} else {
|
||||
// Comprar datos de los ficheros
|
||||
if (!(fn->flags & FileFlag_Normal)) {
|
||||
fn->estado = EstadoFichero_Modificado;
|
||||
fn->flags |= FileFlag_Normal;
|
||||
fn->flags &= ~FileFlag_Directorio;
|
||||
if (!(fileNode->flags & FileFlag_Normal)) {
|
||||
fileNode->estado = FileStatus_Modified;
|
||||
fileNode->flags |= FileFlag_Normal;
|
||||
fileNode->flags &= ~FileFlag_Directory;
|
||||
}
|
||||
size = File_TamanhoFichero(path);
|
||||
if (size != fn->size) {
|
||||
fn->estado = EstadoFichero_Modificado;
|
||||
fn->size = size;
|
||||
size = File_GetSize(filePath);
|
||||
if (size != fileNode->size) {
|
||||
fileNode->estado = FileStatus_Modified;
|
||||
fileNode->size = size;
|
||||
}
|
||||
ft = FileTime_Get(path);
|
||||
if (ft != fn->ft) {
|
||||
fn->estado = EstadoFichero_Modificado;
|
||||
fn->ft = ft;
|
||||
fileTime = FileTime_Get(filePath);
|
||||
if (fileTime != fileNode->fileTime) {
|
||||
fileNode->estado = FileStatus_Modified;
|
||||
fileNode->fileTime = fileTime;
|
||||
}
|
||||
if (fn->estado == EstadoFichero_Modificado) {
|
||||
fn->flags &= ~FileFlag_TieneCRC;
|
||||
if (fileNode->estado == FileStatus_Modified) {
|
||||
fileNode->flags &= ~FileFlag_HasCRC;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (fn);
|
||||
return (fileNode);
|
||||
}
|
||||
|
||||
int FileNode_Refresh_Iterate(char *path, char *name, void *d) {
|
||||
FileNode *fn = d;
|
||||
FileNode *fn_child;
|
||||
FileNode *fileNode = d;
|
||||
FileNode *fileNodeChild;
|
||||
|
||||
if (!strcmp(name, FileNode_Filename)) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
// Buscar el fichero entre los del arbol
|
||||
fn_child = fn->child;
|
||||
while (fn_child) {
|
||||
if (!strcmp(fn_child->name, name)) {
|
||||
fileNodeChild = fileNode->child;
|
||||
while (fileNodeChild) {
|
||||
if (!strcmp(fileNodeChild->name, name)) {
|
||||
break;
|
||||
}
|
||||
fn_child = fn_child->sig;
|
||||
fileNodeChild = fileNodeChild->next;
|
||||
}
|
||||
if (fn_child) {
|
||||
if (fileNodeChild) {
|
||||
// Existe, refrescar
|
||||
FileNode_Refresh(fn_child, path);
|
||||
FileNode_Refresh(fileNodeChild, path);
|
||||
} else {
|
||||
// Nuevo, construir
|
||||
fn_child = FileNode_Refresh(NULL, path);
|
||||
FileNode_AddChild(fn, fn_child);
|
||||
fileNodeChild = FileNode_Refresh(NULL, path);
|
||||
FileNode_AddChild(fileNode, fileNodeChild);
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
||||
58
filenode.h
58
filenode.h
@@ -5,56 +5,52 @@
|
||||
|
||||
#define FileNode_Version 4
|
||||
|
||||
#define FileFlag_Raiz 1
|
||||
#define FileFlag_Root 1
|
||||
#define FileFlag_Normal 2
|
||||
#define FileFlag_Directorio 4
|
||||
#define FileFlag_TieneTamanho 8
|
||||
#define FileFlag_TieneFecha 16
|
||||
#define FileFlag_TieneCRC 32
|
||||
#define FileFlag_MarcaRevision 1024
|
||||
#define FileFlag_Directory 4
|
||||
#define FileFlag_HasSize 8
|
||||
#define FileFlag_HastTime 16
|
||||
#define FileFlag_HasCRC 32
|
||||
#define FileFlag_MarkerForReview 1024
|
||||
|
||||
typedef enum {
|
||||
EstadoFichero_Nada,
|
||||
EstadoFichero_Nuevo,
|
||||
EstadoFichero_Modificado,
|
||||
EstadoFichero_Borrado
|
||||
} EstadoFichero;
|
||||
FileStatus_None,
|
||||
FileStatus_New,
|
||||
FileStatus_Modified,
|
||||
FileStatus_Deleted
|
||||
} FileStatus;
|
||||
|
||||
typedef struct FileNode_Tag {
|
||||
typedef struct SFileNode {
|
||||
char name[MaxFilename];
|
||||
|
||||
int flags;
|
||||
|
||||
EstadoFichero estado;
|
||||
FileStatus estado;
|
||||
|
||||
long long size;
|
||||
|
||||
unsigned long crc;
|
||||
FileTime fileTime;
|
||||
|
||||
FileTime ft;
|
||||
struct SFileNode *child;
|
||||
int childCount;
|
||||
|
||||
struct FileNode_Tag *child;
|
||||
int n_childs;
|
||||
|
||||
struct FileNode_Tag *sig;
|
||||
struct FileNode_Tag *padre;
|
||||
struct SFileNode *next;
|
||||
struct SFileNode *parent;
|
||||
} FileNode;
|
||||
|
||||
FileNode *FileNode_New();
|
||||
void FileNode_Delete(FileNode *fn);
|
||||
FileNode *FileNode_Create();
|
||||
void FileNode_Delete(FileNode *fileNode);
|
||||
void FileNode_AddChild(FileNode *file, FileNode *file2);
|
||||
|
||||
char *FileNode_GetFullPath(FileNode *fn, char *basePath, char *path);
|
||||
char *FileNode_GetFullPath(FileNode *fileNode, char *basePath, char *path);
|
||||
|
||||
void FileNode_GetTamanho(FileNode *fn, char *file);
|
||||
void FileNode_GetFecha(FileNode *fn, char *file);
|
||||
void FileNode_GetCRC(FileNode *fn, char *file);
|
||||
void FileNode_GetSize(FileNode *fileNode, char *file);
|
||||
void FileNode_GetFecha(FileNode *fileNode, char *file);
|
||||
void FileNode_GetCRC(FileNode *fileNode, char *file);
|
||||
|
||||
void FileNode_Save(FileNode *fn, char *fichero);
|
||||
void FileNode_Save(FileNode *fileNode, char *fichero);
|
||||
FileNode *FileNode_Load(char *fichero);
|
||||
|
||||
void FileNode_PrintNode(FileNode *fn);
|
||||
void FileNode_Print(FileNode *fn);
|
||||
void FileNode_PrintNode(FileNode *fileNode);
|
||||
void FileNode_Print(FileNode *fileNode);
|
||||
|
||||
FileNode *FileNode_Build(char *path);
|
||||
|
||||
|
||||
527
filenodecmp.c
527
filenodecmp.c
@@ -8,105 +8,107 @@
|
||||
#include "filenode.h"
|
||||
#include "filenodecmp.h"
|
||||
|
||||
AccionFileNode *_free_accionfilenode = NULL;
|
||||
int _n_accionfilenode = 0;
|
||||
AccionFileNode *_actionFileNodeFree = NULL;
|
||||
int _actionFileNodeFreeCount = 0;
|
||||
#define AccionFileNode_Tocho 1024
|
||||
AccionFileNode *AccionFileNode_Crear() {
|
||||
AccionFileNode *afn;
|
||||
AccionFileNode *AccionFileNode_Create() {
|
||||
AccionFileNode *actionFileNode;
|
||||
|
||||
if (_free_accionfilenode == NULL ) {
|
||||
AccionFileNode *nodos;
|
||||
if (_actionFileNodeFree == NULL ) {
|
||||
AccionFileNode *actionFileNodeFreeAux;
|
||||
int i;
|
||||
// Reservar un tocho
|
||||
nodos = malloc(sizeof(AccionFileNode) * AccionFileNode_Tocho);
|
||||
actionFileNodeFreeAux = malloc(
|
||||
sizeof(AccionFileNode) * AccionFileNode_Tocho);
|
||||
for (i = 0; i < AccionFileNode_Tocho - 1; i++) {
|
||||
nodos[i].sig = &nodos[i + 1];
|
||||
actionFileNodeFreeAux[i].next = &actionFileNodeFreeAux[i + 1];
|
||||
}
|
||||
nodos[AccionFileNode_Tocho - 1].sig = NULL;
|
||||
_free_accionfilenode = &nodos[0];
|
||||
actionFileNodeFreeAux[AccionFileNode_Tocho - 1].next = NULL;
|
||||
_actionFileNodeFree = &actionFileNodeFreeAux[0];
|
||||
}
|
||||
|
||||
// Obtener el primero libre
|
||||
afn = _free_accionfilenode;
|
||||
_free_accionfilenode = afn->sig;
|
||||
_n_accionfilenode++;
|
||||
actionFileNode = _actionFileNodeFree;
|
||||
_actionFileNodeFree = actionFileNode->next;
|
||||
_actionFileNodeFreeCount++;
|
||||
|
||||
// Iniciar
|
||||
afn->accion = AccionFileCmp_Nada;
|
||||
afn->izquierda = NULL;
|
||||
afn->derecha = NULL;
|
||||
afn->sig = NULL;
|
||||
actionFileNode->action = AccionFileCmp_Nothing;
|
||||
actionFileNode->left = NULL;
|
||||
actionFileNode->right = NULL;
|
||||
actionFileNode->next = NULL;
|
||||
|
||||
return (afn);
|
||||
return (actionFileNode);
|
||||
}
|
||||
|
||||
void AccionFileNode_Destruir(AccionFileNode *afn) {
|
||||
afn->sig = _free_accionfilenode;
|
||||
_free_accionfilenode = afn;
|
||||
_n_accionfilenode--;
|
||||
void AccionFileNode_Destroy(AccionFileNode *actionFileNode) {
|
||||
actionFileNode->next = _actionFileNodeFree;
|
||||
_actionFileNodeFree = actionFileNode;
|
||||
_actionFileNodeFreeCount--;
|
||||
}
|
||||
|
||||
AccionFileNode *AccionFileNode_CrearNormal(FileNode *fnIzq, FileNode *fnDer) {
|
||||
AccionFileNode *afnNew;
|
||||
afnNew = AccionFileNode_Crear();
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
afnNew->izquierda = fnIzq;
|
||||
afnNew->derecha = fnDer;
|
||||
return afnNew;
|
||||
AccionFileNode *AccionFileNode_CreateNormal(FileNode *fileNodeLeft,
|
||||
FileNode *fileNodeRight) {
|
||||
AccionFileNode *actionFileNode;
|
||||
actionFileNode = AccionFileNode_Create();
|
||||
actionFileNode->action = AccionFileCmp_Nothing;
|
||||
actionFileNode->left = fileNodeLeft;
|
||||
actionFileNode->right = fileNodeRight;
|
||||
return actionFileNode;
|
||||
}
|
||||
|
||||
void AccionFileNode_CompareChilds(AccionFileNode *afnRaiz,
|
||||
AccionFileNode **afnCola,
|
||||
void (*CheckPair)(FileNode *fnIzq, FileNode *fnDer,
|
||||
AccionFileNode **afnCola)) {
|
||||
FileNode *fnIzq, *fnDer;
|
||||
AccionFileNode *afnColaStart = (*afnCola);
|
||||
void AccionFileNode_CompareChilds(AccionFileNode *actionFileNodeRoot,
|
||||
AccionFileNode **actionFileNodeQueue,
|
||||
void (*CheckPair)(FileNode *fileNodeLeft, FileNode *fileNodeRight,
|
||||
AccionFileNode **actionFileNodeQueue)) {
|
||||
FileNode *fileNodeLeft, *fileNodeRight;
|
||||
AccionFileNode *actionFileNodeQueueStart = (*actionFileNodeQueue);
|
||||
|
||||
// Comprobar si hay algo que comparar
|
||||
if (!afnRaiz->izquierda && !afnRaiz->derecha) {
|
||||
if (!actionFileNodeRoot->left && !actionFileNodeRoot->right) {
|
||||
// Nada que hacer
|
||||
return;
|
||||
}
|
||||
|
||||
// Iterar todos los nodos de la izquierda
|
||||
if (afnRaiz->izquierda) {
|
||||
fnIzq = afnRaiz->izquierda->child;
|
||||
while (fnIzq) {
|
||||
if (afnRaiz->derecha) {
|
||||
fnDer = afnRaiz->derecha->child;
|
||||
while (fnDer) {
|
||||
if (!strcmp(fnIzq->name, fnDer->name)) {
|
||||
if (actionFileNodeRoot->left) {
|
||||
fileNodeLeft = actionFileNodeRoot->left->child;
|
||||
while (fileNodeLeft) {
|
||||
if (actionFileNodeRoot->right) {
|
||||
fileNodeRight = actionFileNodeRoot->right->child;
|
||||
while (fileNodeRight) {
|
||||
if (!strcmp(fileNodeLeft->name, fileNodeRight->name)) {
|
||||
break;
|
||||
} else {
|
||||
fnDer = fnDer->sig;
|
||||
fileNodeRight = fileNodeRight->next;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fnDer = NULL;
|
||||
fileNodeRight = NULL;
|
||||
}
|
||||
|
||||
CheckPair(fnIzq, fnDer, afnCola);
|
||||
CheckPair(fileNodeLeft, fileNodeRight, actionFileNodeQueue);
|
||||
|
||||
fnIzq = fnIzq->sig;
|
||||
fileNodeLeft = fileNodeLeft->next;
|
||||
}
|
||||
}
|
||||
|
||||
// Iterar todos los nodos de la derecha,
|
||||
// ignorando las comparaciones ya realizadas
|
||||
if (afnRaiz->derecha) {
|
||||
fnDer = afnRaiz->derecha->child;
|
||||
while (fnDer) {
|
||||
if (actionFileNodeRoot->right) {
|
||||
fileNodeRight = actionFileNodeRoot->right->child;
|
||||
while (fileNodeRight) {
|
||||
int doCheck = 1;
|
||||
if (afnRaiz->izquierda) {
|
||||
fnIzq = afnRaiz->izquierda->child;
|
||||
while (fnIzq) {
|
||||
AccionFileNode *afnCheck = afnColaStart;
|
||||
if (actionFileNodeRoot->left) {
|
||||
fileNodeLeft = actionFileNodeRoot->left->child;
|
||||
while (fileNodeLeft) {
|
||||
AccionFileNode *afnCheck = actionFileNodeQueueStart;
|
||||
while (afnCheck) {
|
||||
if (afnCheck->izquierda == fnIzq
|
||||
&& afnCheck->derecha == fnDer) {
|
||||
if (afnCheck->left == fileNodeLeft
|
||||
&& afnCheck->right == fileNodeRight) {
|
||||
break;
|
||||
} else {
|
||||
afnCheck = afnCheck->sig;
|
||||
afnCheck = afnCheck->next;
|
||||
}
|
||||
}
|
||||
if (afnCheck) {
|
||||
@@ -114,21 +116,21 @@ void AccionFileNode_CompareChilds(AccionFileNode *afnRaiz,
|
||||
break;
|
||||
}
|
||||
|
||||
if (!strcmp(fnIzq->name, fnDer->name)) {
|
||||
if (!strcmp(fileNodeLeft->name, fileNodeRight->name)) {
|
||||
break;
|
||||
} else {
|
||||
fnIzq = fnIzq->sig;
|
||||
fileNodeLeft = fileNodeLeft->next;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fnIzq = NULL;
|
||||
fileNodeLeft = NULL;
|
||||
}
|
||||
|
||||
if (doCheck) {
|
||||
CheckPair(fnIzq, fnDer, afnCola);
|
||||
CheckPair(fileNodeLeft, fileNodeRight, actionFileNodeQueue);
|
||||
}
|
||||
|
||||
fnDer = fnDer->sig;
|
||||
fileNodeRight = fileNodeRight->next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,47 +138,47 @@ void AccionFileNode_CompareChilds(AccionFileNode *afnRaiz,
|
||||
|
||||
void AccionFileNode_DeletePair(FileNode *fnIzq, FileNode *fnDer,
|
||||
AccionFileNode **afnCola) {
|
||||
AccionFileNode *afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
||||
AccionFileNode *afnNew = AccionFileNode_CreateNormal(fnIzq, fnDer);
|
||||
|
||||
if (!fnIzq && !fnDer) {
|
||||
AccionFileNode_Destruir(afnNew);
|
||||
AccionFileNode_Destroy(afnNew);
|
||||
return;
|
||||
}
|
||||
if (!fnIzq && fnDer) {
|
||||
if (fnDer->flags & FileFlag_Directorio) {
|
||||
if (fnDer->flags & FileFlag_Directory) {
|
||||
// Iterar hijos para borrarlos
|
||||
AccionFileNode_CompareChilds(afnNew, afnCola,
|
||||
AccionFileNode_DeletePair);
|
||||
}
|
||||
|
||||
if (fnDer->estado != EstadoFichero_Borrado) {
|
||||
if (fnDer->estado != FileStatus_Deleted) {
|
||||
// Accion de borrado para el nodo
|
||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||
(*afnCola)->sig = afnNew;
|
||||
afnNew->action = AccionFileCmp_DeleteRight;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
} else {
|
||||
AccionFileNode_Destruir(afnNew);
|
||||
AccionFileNode_Destroy(afnNew);
|
||||
}
|
||||
}
|
||||
if (fnIzq && !fnDer) {
|
||||
if (fnIzq->flags & FileFlag_Directorio) {
|
||||
if (fnIzq->flags & FileFlag_Directory) {
|
||||
// Iterar hijos para borrarlos
|
||||
AccionFileNode_CompareChilds(afnNew, afnCola,
|
||||
AccionFileNode_DeletePair);
|
||||
}
|
||||
|
||||
if (fnIzq->estado != EstadoFichero_Borrado) {
|
||||
if (fnIzq->estado != FileStatus_Deleted) {
|
||||
// Accion de borrado para el nodo
|
||||
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
||||
(*afnCola)->sig = afnNew;
|
||||
afnNew->action = AccionFileCmp_DeleteLeft;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
} else {
|
||||
AccionFileNode_Destruir(afnNew);
|
||||
AccionFileNode_Destroy(afnNew);
|
||||
}
|
||||
}
|
||||
if (fnIzq && fnDer) {
|
||||
if ((fnIzq->flags & FileFlag_Directorio)
|
||||
|| (fnDer->flags & FileFlag_Directorio)) {
|
||||
if ((fnIzq->flags & FileFlag_Directory)
|
||||
|| (fnDer->flags & FileFlag_Directory)) {
|
||||
// Alguno es directorio
|
||||
|
||||
// Iterar hijos para borrarlos
|
||||
@@ -184,52 +186,52 @@ void AccionFileNode_DeletePair(FileNode *fnIzq, FileNode *fnDer,
|
||||
AccionFileNode_DeletePair);
|
||||
}
|
||||
|
||||
if (fnIzq->estado != EstadoFichero_Borrado) {
|
||||
if (fnIzq->estado != FileStatus_Deleted) {
|
||||
// Accion de borrado para el nodo izquierdo
|
||||
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
||||
(*afnCola)->sig = afnNew;
|
||||
afnNew->action = AccionFileCmp_DeleteLeft;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
afnNew = NULL;
|
||||
}
|
||||
if (fnDer->estado != EstadoFichero_Borrado) {
|
||||
if (fnDer->estado != FileStatus_Deleted) {
|
||||
if (!afnNew) {
|
||||
afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
||||
afnNew = AccionFileNode_CreateNormal(fnIzq, fnDer);
|
||||
}
|
||||
// Accion de borrado para el nodo derecho
|
||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||
(*afnCola)->sig = afnNew;
|
||||
afnNew->action = AccionFileCmp_DeleteRight;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
afnNew = NULL;
|
||||
}
|
||||
if (afnNew) {
|
||||
AccionFileNode_Destruir(afnNew);
|
||||
AccionFileNode_Destroy(afnNew);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AccionFileNode_CheckPair(FileNode *fnIzq, FileNode *fnDer,
|
||||
AccionFileNode **afnCola) {
|
||||
AccionFileNode *afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
||||
AccionFileNode *afnNew = AccionFileNode_CreateNormal(fnIzq, fnDer);
|
||||
|
||||
if (!fnIzq && !fnDer) {
|
||||
AccionFileNode_Destruir(afnNew);
|
||||
AccionFileNode_Destroy(afnNew);
|
||||
return;
|
||||
}
|
||||
if (!fnIzq && fnDer) {
|
||||
if (fnDer->flags & FileFlag_Directorio) {
|
||||
if (fnDer->flags & FileFlag_Directory) {
|
||||
// Directory
|
||||
if (fnDer->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
if (fnDer->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
|
||||
// Anhadir a la lista de acciones
|
||||
(*afnCola)->sig = afnNew;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
|
||||
} else {
|
||||
afnNew->accion = AccionFileCmp_CrearDirIzquierda;
|
||||
afnNew->action = AccionFileCmp_MakeLeftDirectory;
|
||||
|
||||
// Anhadir a la lista de acciones
|
||||
(*afnCola)->sig = afnNew;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
|
||||
// Iterar hijos
|
||||
@@ -237,37 +239,37 @@ void AccionFileNode_CheckPair(FileNode *fnIzq, FileNode *fnDer,
|
||||
AccionFileNode_CheckPair);
|
||||
|
||||
// Crear nueva accion para copiar la fecha
|
||||
afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
||||
afnNew->accion = AccionFileCmp_FechaDerechaAIzquierda;
|
||||
(*afnCola)->sig = afnNew;
|
||||
afnNew = AccionFileNode_CreateNormal(fnIzq, fnDer);
|
||||
afnNew->action = AccionFileCmp_DateRightToLeft;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
}
|
||||
} else {
|
||||
// File
|
||||
if (fnDer->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
if (fnDer->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
} else {
|
||||
afnNew->accion = AccionFileCmp_DerechaAIzquierda;
|
||||
afnNew->action = AccionFileCmp_RightToLeft;
|
||||
}
|
||||
(*afnCola)->sig = afnNew;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
}
|
||||
}
|
||||
if (fnIzq && !fnDer) {
|
||||
if (fnIzq->flags & FileFlag_Directorio) {
|
||||
if (fnIzq->flags & FileFlag_Directory) {
|
||||
// Directory
|
||||
if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
if (fnIzq->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
|
||||
// Anhadir a la lista de acciones
|
||||
(*afnCola)->sig = afnNew;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
|
||||
} else {
|
||||
afnNew->accion = AccionFileCmp_CrearDirDerecha;
|
||||
afnNew->action = AccionFileCmp_MakeRightDirectory;
|
||||
|
||||
// Anhadir a la lista de acciones
|
||||
(*afnCola)->sig = afnNew;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
|
||||
// Iterar hijos
|
||||
@@ -275,68 +277,68 @@ void AccionFileNode_CheckPair(FileNode *fnIzq, FileNode *fnDer,
|
||||
AccionFileNode_CheckPair);
|
||||
|
||||
// Crear nueva accion para copiar la fecha
|
||||
afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
||||
afnNew->accion = AccionFileCmp_FechaIzquierdaADerecha;
|
||||
(*afnCola)->sig = afnNew;
|
||||
afnNew = AccionFileNode_CreateNormal(fnIzq, fnDer);
|
||||
afnNew->action = AccionFileCmp_DateLeftToRight;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
}
|
||||
} else {
|
||||
// File
|
||||
if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
if (fnIzq->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
} else {
|
||||
afnNew->accion = AccionFileCmp_IzquierdaADerecha;
|
||||
afnNew->action = AccionFileCmp_LeftToRight;
|
||||
}
|
||||
(*afnCola)->sig = afnNew;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
}
|
||||
}
|
||||
if (fnIzq && fnDer) {
|
||||
if ((fnIzq->flags & FileFlag_Directorio)
|
||||
&& (fnDer->flags & FileFlag_Directorio)) {
|
||||
if ((fnIzq->flags & FileFlag_Directory)
|
||||
&& (fnDer->flags & FileFlag_Directory)) {
|
||||
// Directorios
|
||||
|
||||
// Preparar accion para el par de directorios
|
||||
if (abs(fnIzq->ft - fnDer->ft) <= 1) { // appoximadamente iguales
|
||||
if (fnDer->estado == EstadoFichero_Borrado
|
||||
&& fnIzq->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
} else if (fnDer->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
||||
if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
if (abs(fnIzq->fileTime - fnDer->fileTime) <= 1) { // appoximadamente iguales
|
||||
if (fnDer->estado == FileStatus_Deleted
|
||||
&& fnIzq->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
} else if (fnDer->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_DeleteLeft;
|
||||
if (fnIzq->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
} else if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||
if (fnDer->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
} else if (fnIzq->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_DeleteRight;
|
||||
if (fnDer->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
} else {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
} else if (fnIzq->ft < fnDer->ft) {
|
||||
afnNew->accion = AccionFileCmp_FechaDerechaAIzquierda;
|
||||
if (fnDer->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
||||
if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
} else if (fnIzq->fileTime < fnDer->fileTime) {
|
||||
afnNew->action = AccionFileCmp_DateRightToLeft;
|
||||
if (fnDer->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_DeleteLeft;
|
||||
if (fnIzq->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
} else if (fnIzq->ft > fnDer->ft) {
|
||||
afnNew->accion = AccionFileCmp_FechaIzquierdaADerecha;
|
||||
if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||
if (fnDer->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
} else if (fnIzq->fileTime > fnDer->fileTime) {
|
||||
afnNew->action = AccionFileCmp_DateLeftToRight;
|
||||
if (fnIzq->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_DeleteRight;
|
||||
if (fnDer->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Procesar nodos hijos
|
||||
if (afnNew->accion == AccionFileCmp_BorrarDerecha
|
||||
|| afnNew->accion == AccionFileCmp_BorrarIzquierda
|
||||
|| (fnIzq->estado == EstadoFichero_Borrado
|
||||
&& fnDer->estado == EstadoFichero_Borrado)) {
|
||||
if (afnNew->action == AccionFileCmp_DeleteRight
|
||||
|| afnNew->action == AccionFileCmp_DeleteLeft
|
||||
|| (fnIzq->estado == FileStatus_Deleted
|
||||
&& fnDer->estado == FileStatus_Deleted)) {
|
||||
// Iterar nodos hijos para borrarlos
|
||||
AccionFileNode_CompareChilds(afnNew, afnCola,
|
||||
AccionFileNode_DeletePair);
|
||||
@@ -346,7 +348,7 @@ void AccionFileNode_CheckPair(FileNode *fnIzq, FileNode *fnDer,
|
||||
}
|
||||
|
||||
// Encolar accion para el directorio padre
|
||||
(*afnCola)->sig = afnNew;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
|
||||
} else if ((fnIzq->flags & FileFlag_Normal)
|
||||
@@ -354,43 +356,43 @@ void AccionFileNode_CheckPair(FileNode *fnIzq, FileNode *fnDer,
|
||||
// Ficheros
|
||||
|
||||
// Preparar accion para el par de ficheros
|
||||
if (abs(fnIzq->ft - fnDer->ft) <= 1) { // appoximadamente iguales
|
||||
if (fnDer->estado == EstadoFichero_Borrado
|
||||
&& fnIzq->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
} else if (fnDer->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
||||
if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
if (abs(fnIzq->fileTime - fnDer->fileTime) <= 1) { // appoximadamente iguales
|
||||
if (fnDer->estado == FileStatus_Deleted
|
||||
&& fnIzq->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
} else if (fnDer->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_DeleteLeft;
|
||||
if (fnIzq->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
} else if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||
if (fnDer->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
} else if (fnIzq->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_DeleteRight;
|
||||
if (fnDer->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
} else {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
} else if (fnIzq->ft < fnDer->ft) {
|
||||
afnNew->accion = AccionFileCmp_DerechaAIzquierda;
|
||||
if (fnDer->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
||||
if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
} else if (fnIzq->fileTime < fnDer->fileTime) {
|
||||
afnNew->action = AccionFileCmp_RightToLeft;
|
||||
if (fnDer->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_DeleteLeft;
|
||||
if (fnIzq->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
} else if (fnIzq->ft > fnDer->ft) {
|
||||
afnNew->accion = AccionFileCmp_IzquierdaADerecha;
|
||||
if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||
if (fnDer->estado == EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
} else if (fnIzq->fileTime > fnDer->fileTime) {
|
||||
afnNew->action = AccionFileCmp_LeftToRight;
|
||||
if (fnIzq->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_DeleteRight;
|
||||
if (fnDer->estado == FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Encolar accion para el fichero
|
||||
(*afnCola)->sig = afnNew;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
|
||||
} else {
|
||||
@@ -402,7 +404,7 @@ void AccionFileNode_CheckPair(FileNode *fnIzq, FileNode *fnDer,
|
||||
}
|
||||
|
||||
AccionFileNode *AccionFileNode_BuildSync(FileNode *izquierda, FileNode *derecha) {
|
||||
AccionFileNode *afnRaiz = AccionFileNode_CrearNormal(izquierda, derecha);
|
||||
AccionFileNode *afnRaiz = AccionFileNode_CreateNormal(izquierda, derecha);
|
||||
AccionFileNode *afnCola = afnRaiz;
|
||||
|
||||
AccionFileNode_CompareChilds(afnRaiz, &afnCola, AccionFileNode_CheckPair);
|
||||
@@ -412,128 +414,131 @@ AccionFileNode *AccionFileNode_BuildSync(FileNode *izquierda, FileNode *derecha)
|
||||
|
||||
void AccionFileNode_Copy(FileNode *fnIzq, FileNode *fnDer,
|
||||
AccionFileNode **afnCola) {
|
||||
AccionFileNode *afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
||||
AccionFileNode *afnNew = AccionFileNode_CreateNormal(fnIzq, fnDer);
|
||||
|
||||
if (!fnIzq && !fnDer) {
|
||||
AccionFileNode_Destruir(afnNew);
|
||||
AccionFileNode_Destroy(afnNew);
|
||||
return;
|
||||
}
|
||||
if (!fnIzq && fnDer) {
|
||||
if (fnDer->flags & FileFlag_Directorio) {
|
||||
if (fnDer->flags & FileFlag_Directory) {
|
||||
AccionFileNode_CompareChilds(afnNew, afnCola,
|
||||
AccionFileNode_DeletePair);
|
||||
}
|
||||
|
||||
if (fnDer->estado != EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||
if (fnDer->estado != FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_DeleteRight;
|
||||
} else {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
(*afnCola)->sig = afnNew;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
}
|
||||
if (fnIzq && !fnDer) {
|
||||
if (fnIzq->estado != EstadoFichero_Borrado) {
|
||||
if (fnIzq->flags & FileFlag_Directorio) {
|
||||
afnNew->accion = AccionFileCmp_CrearDirDerecha;
|
||||
(*afnCola)->sig = afnNew;
|
||||
if (fnIzq->estado != FileStatus_Deleted) {
|
||||
if (fnIzq->flags & FileFlag_Directory) {
|
||||
afnNew->action = AccionFileCmp_MakeRightDirectory;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
AccionFileNode_CompareChilds(afnNew, afnCola,
|
||||
AccionFileNode_Copy);
|
||||
afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
||||
afnNew->accion = AccionFileCmp_FechaIzquierdaADerecha;
|
||||
afnNew = AccionFileNode_CreateNormal(fnIzq, fnDer);
|
||||
afnNew->action = AccionFileCmp_DateLeftToRight;
|
||||
} else {
|
||||
afnNew->accion = AccionFileCmp_IzquierdaADerecha;
|
||||
afnNew->action = AccionFileCmp_LeftToRight;
|
||||
}
|
||||
} else {
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
}
|
||||
(*afnCola)->sig = afnNew;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
}
|
||||
if (fnIzq && fnDer) {
|
||||
if ((fnIzq->flags & FileFlag_Directorio)
|
||||
|| (fnDer->flags & FileFlag_Directorio)) {
|
||||
if (fnIzq->estado != EstadoFichero_Borrado) {
|
||||
if ((fnIzq->flags & FileFlag_Directory)
|
||||
|| (fnDer->flags & FileFlag_Directory)) {
|
||||
if (fnIzq->estado != FileStatus_Deleted) {
|
||||
AccionFileNode_CompareChilds(afnNew, afnCola,
|
||||
AccionFileNode_Copy);
|
||||
if (abs(fnIzq->ft - fnDer->ft) <= 1) { // appox. equal
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
if (abs(fnIzq->fileTime - fnDer->fileTime) <= 1) { // appox. equal
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
} else {
|
||||
afnNew->accion = AccionFileCmp_FechaIzquierdaADerecha;
|
||||
afnNew->action = AccionFileCmp_DateLeftToRight;
|
||||
}
|
||||
} else {
|
||||
AccionFileNode_CompareChilds(afnNew, afnCola,
|
||||
AccionFileNode_DeletePair);
|
||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||
afnNew->action = AccionFileCmp_DeleteRight;
|
||||
}
|
||||
} else {
|
||||
if (fnIzq->estado != EstadoFichero_Borrado) {
|
||||
if (abs(fnIzq->ft - fnDer->ft) <= 1) { // appox. equal
|
||||
afnNew->accion = AccionFileCmp_Nada;
|
||||
if (fnIzq->estado != FileStatus_Deleted) {
|
||||
if (abs(fnIzq->fileTime - fnDer->fileTime) <= 1) { // appox. equal
|
||||
afnNew->action = AccionFileCmp_Nothing;
|
||||
} else {
|
||||
afnNew->accion = AccionFileCmp_IzquierdaADerecha;
|
||||
afnNew->action = AccionFileCmp_LeftToRight;
|
||||
}
|
||||
} else {
|
||||
if (fnDer->estado != EstadoFichero_Borrado) {
|
||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||
if (fnDer->estado != FileStatus_Deleted) {
|
||||
afnNew->action = AccionFileCmp_DeleteRight;
|
||||
}
|
||||
}
|
||||
}
|
||||
(*afnCola)->sig = afnNew;
|
||||
(*afnCola)->next = afnNew;
|
||||
(*afnCola) = afnNew;
|
||||
}
|
||||
}
|
||||
|
||||
AccionFileNode *AccionFileNode_BuildCopy(FileNode *izquierda, FileNode *derecha) {
|
||||
AccionFileNode *afnRaiz = AccionFileNode_CrearNormal(izquierda, derecha);
|
||||
AccionFileNode *afnCola = afnRaiz;
|
||||
AccionFileNode *AccionFileNode_BuildCopy(FileNode *fileNodeLeft,
|
||||
FileNode *fileNodeRight) {
|
||||
AccionFileNode *actionFileNodeRoot = AccionFileNode_CreateNormal(
|
||||
fileNodeLeft, fileNodeRight);
|
||||
AccionFileNode *actionFileNodeQueue = actionFileNodeRoot;
|
||||
|
||||
AccionFileNode_CompareChilds(afnRaiz, &afnCola, AccionFileNode_Copy);
|
||||
AccionFileNode_CompareChilds(actionFileNodeRoot, &actionFileNodeQueue,
|
||||
AccionFileNode_Copy);
|
||||
|
||||
return afnRaiz;
|
||||
return actionFileNodeRoot;
|
||||
}
|
||||
|
||||
void AccionFileNode_Print(AccionFileNode *afn) {
|
||||
void AccionFileNode_Print(AccionFileNode *actionFileNode) {
|
||||
char showPath[MaxPath];
|
||||
while (afn != NULL ) {
|
||||
if (afn->izquierda) {
|
||||
FileNode_GetFullPath(afn->izquierda, "", showPath);
|
||||
while (actionFileNode != NULL ) {
|
||||
if (actionFileNode->left) {
|
||||
FileNode_GetFullPath(actionFileNode->left, "", showPath);
|
||||
} else {
|
||||
FileNode_GetFullPath(afn->derecha, "", showPath);
|
||||
FileNode_GetFullPath(actionFileNode->right, "", showPath);
|
||||
}
|
||||
|
||||
switch (afn->accion) {
|
||||
case AccionFileCmp_Nada:
|
||||
switch (actionFileNode->action) {
|
||||
case AccionFileCmp_Nothing:
|
||||
//printf("%s == %s\n",pathIzq,pathDer);
|
||||
break;
|
||||
case AccionFileCmp_IzquierdaADerecha:
|
||||
case AccionFileCmp_LeftToRight:
|
||||
printf(" => %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_DerechaAIzquierda:
|
||||
case AccionFileCmp_RightToLeft:
|
||||
printf(" <= %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_BorrarIzquierda:
|
||||
case AccionFileCmp_DeleteLeft:
|
||||
printf(" *- %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_BorrarDerecha:
|
||||
case AccionFileCmp_DeleteRight:
|
||||
printf(" -* %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_FechaIzquierdaADerecha:
|
||||
case AccionFileCmp_DateLeftToRight:
|
||||
printf(" -> %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_FechaDerechaAIzquierda:
|
||||
case AccionFileCmp_DateRightToLeft:
|
||||
printf(" <- %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_CrearDirDerecha:
|
||||
case AccionFileCmp_MakeRightDirectory:
|
||||
printf(" -D %s\n", showPath);
|
||||
break;
|
||||
case AccionFileCmp_CrearDirIzquierda:
|
||||
case AccionFileCmp_MakeLeftDirectory:
|
||||
printf(" D- %s\n", showPath);
|
||||
break;
|
||||
}
|
||||
|
||||
afn = afn->sig;
|
||||
actionFileNode = actionFileNode->next;
|
||||
}
|
||||
printf("End\n");
|
||||
}
|
||||
@@ -544,82 +549,84 @@ void AccionFileNodeAux_CopyDate(char *pathOrig, char *pathDest) {
|
||||
}
|
||||
|
||||
void AccionFileNodeAux_Copy(char *pathOrig, char *pathDest) {
|
||||
if (File_Copiar(pathOrig, pathDest)) {
|
||||
if (File_Copy(pathOrig, pathDest)) {
|
||||
AccionFileNodeAux_CopyDate(pathOrig, pathDest);
|
||||
} else {
|
||||
File_Borrar(pathDest);
|
||||
File_Delete(pathDest);
|
||||
}
|
||||
}
|
||||
void AccionFileNodeAux_Delete(char *pathOrig, char *pathDest) {
|
||||
if (File_EsDirectorio(pathDest)) {
|
||||
File_BorrarDirectorio(pathDest);
|
||||
if (File_IsDirectory(pathDest)) {
|
||||
File_DeleteDirectory(pathDest);
|
||||
} else {
|
||||
File_Borrar(pathDest);
|
||||
File_Delete(pathDest);
|
||||
}
|
||||
}
|
||||
void AccionFileNodeAux_MakeDir(char *pathOrig, char *pathDest) {
|
||||
File_CrearDir(pathDest);
|
||||
File_MakeDirectory(pathDest);
|
||||
}
|
||||
|
||||
void AccionFileNode_RunList(AccionFileNode *afn, char *pathIzquierda,
|
||||
char *pathDerecha) {
|
||||
char pathIzq[MaxPath], pathDer[MaxPath], showPath[MaxPath];
|
||||
while (afn != NULL ) {
|
||||
if (afn->izquierda) {
|
||||
FileNode_GetFullPath(afn->izquierda, pathIzquierda, pathIzq);
|
||||
void AccionFileNode_RunList(AccionFileNode *actionFileNode, char *pathLeft,
|
||||
char *pathRight) {
|
||||
char fullPathLeft[MaxPath], fullPathRight[MaxPath], showPath[MaxPath];
|
||||
while (actionFileNode != NULL ) {
|
||||
if (actionFileNode->left) {
|
||||
FileNode_GetFullPath(actionFileNode->left, pathLeft, fullPathLeft);
|
||||
} else {
|
||||
FileNode_GetFullPath(afn->derecha, pathIzquierda, pathIzq);
|
||||
FileNode_GetFullPath(actionFileNode->right, pathLeft, fullPathLeft);
|
||||
}
|
||||
if (afn->derecha) {
|
||||
FileNode_GetFullPath(afn->derecha, pathDerecha, pathDer);
|
||||
if (actionFileNode->right) {
|
||||
FileNode_GetFullPath(actionFileNode->right, pathRight,
|
||||
fullPathRight);
|
||||
} else {
|
||||
FileNode_GetFullPath(afn->izquierda, pathDerecha, pathDer);
|
||||
FileNode_GetFullPath(actionFileNode->left, pathRight,
|
||||
fullPathRight);
|
||||
}
|
||||
if (afn->izquierda) {
|
||||
FileNode_GetFullPath(afn->izquierda, "", showPath);
|
||||
if (actionFileNode->left) {
|
||||
FileNode_GetFullPath(actionFileNode->left, "", showPath);
|
||||
} else {
|
||||
FileNode_GetFullPath(afn->derecha, "", showPath);
|
||||
FileNode_GetFullPath(actionFileNode->right, "", showPath);
|
||||
}
|
||||
|
||||
switch (afn->accion) {
|
||||
case AccionFileCmp_Nada:
|
||||
switch (actionFileNode->action) {
|
||||
case AccionFileCmp_Nothing:
|
||||
//printf("%s == %s\n",pathIzq,pathDer);
|
||||
break;
|
||||
case AccionFileCmp_IzquierdaADerecha:
|
||||
case AccionFileCmp_LeftToRight:
|
||||
printf(" => %s\n", showPath);
|
||||
AccionFileNodeAux_Copy(pathIzq, pathDer);
|
||||
AccionFileNodeAux_Copy(fullPathLeft, fullPathRight);
|
||||
break;
|
||||
case AccionFileCmp_DerechaAIzquierda:
|
||||
case AccionFileCmp_RightToLeft:
|
||||
printf(" <= %s\n", showPath);
|
||||
AccionFileNodeAux_Copy(pathDer, pathIzq);
|
||||
AccionFileNodeAux_Copy(fullPathRight, fullPathLeft);
|
||||
break;
|
||||
case AccionFileCmp_BorrarIzquierda:
|
||||
case AccionFileCmp_DeleteLeft:
|
||||
printf(" *- %s\n", showPath);
|
||||
AccionFileNodeAux_Delete(pathDer, pathIzq);
|
||||
AccionFileNodeAux_Delete(fullPathRight, fullPathLeft);
|
||||
break;
|
||||
case AccionFileCmp_BorrarDerecha:
|
||||
case AccionFileCmp_DeleteRight:
|
||||
printf(" -* %s\n", showPath);
|
||||
AccionFileNodeAux_Delete(pathIzq, pathDer);
|
||||
AccionFileNodeAux_Delete(fullPathLeft, fullPathRight);
|
||||
break;
|
||||
case AccionFileCmp_FechaIzquierdaADerecha:
|
||||
case AccionFileCmp_DateLeftToRight:
|
||||
printf(" -> %s\n", showPath);
|
||||
AccionFileNodeAux_CopyDate(pathIzq, pathDer);
|
||||
AccionFileNodeAux_CopyDate(fullPathLeft, fullPathRight);
|
||||
break;
|
||||
case AccionFileCmp_FechaDerechaAIzquierda:
|
||||
case AccionFileCmp_DateRightToLeft:
|
||||
printf(" <- %s\n", showPath);
|
||||
AccionFileNodeAux_CopyDate(pathDer, pathIzq);
|
||||
AccionFileNodeAux_CopyDate(fullPathRight, fullPathLeft);
|
||||
break;
|
||||
case AccionFileCmp_CrearDirDerecha:
|
||||
case AccionFileCmp_MakeRightDirectory:
|
||||
printf(" -D %s\n", showPath);
|
||||
AccionFileNodeAux_MakeDir(pathIzq, pathDer);
|
||||
AccionFileNodeAux_MakeDir(fullPathLeft, fullPathRight);
|
||||
break;
|
||||
case AccionFileCmp_CrearDirIzquierda:
|
||||
case AccionFileCmp_MakeLeftDirectory:
|
||||
printf(" D- %s\n", showPath);
|
||||
AccionFileNodeAux_MakeDir(pathDer, pathIzq);
|
||||
AccionFileNodeAux_MakeDir(fullPathRight, fullPathLeft);
|
||||
break;
|
||||
}
|
||||
|
||||
afn = afn->sig;
|
||||
actionFileNode = actionFileNode->next;
|
||||
}
|
||||
printf("End\n");
|
||||
}
|
||||
|
||||
@@ -4,36 +4,37 @@
|
||||
#include "filenode.h"
|
||||
|
||||
typedef enum {
|
||||
AccionFileCmp_Nada,
|
||||
AccionFileCmp_IzquierdaADerecha,
|
||||
AccionFileCmp_DerechaAIzquierda,
|
||||
AccionFileCmp_BorrarIzquierda,
|
||||
AccionFileCmp_BorrarDerecha,
|
||||
AccionFileCmp_FechaIzquierdaADerecha,
|
||||
AccionFileCmp_FechaDerechaAIzquierda,
|
||||
AccionFileCmp_CrearDirDerecha,
|
||||
AccionFileCmp_CrearDirIzquierda
|
||||
AccionFileCmp_Nothing,
|
||||
AccionFileCmp_LeftToRight,
|
||||
AccionFileCmp_RightToLeft,
|
||||
AccionFileCmp_DeleteLeft,
|
||||
AccionFileCmp_DeleteRight,
|
||||
AccionFileCmp_DateLeftToRight,
|
||||
AccionFileCmp_DateRightToLeft,
|
||||
AccionFileCmp_MakeRightDirectory,
|
||||
AccionFileCmp_MakeLeftDirectory
|
||||
} AccionFileCmp;
|
||||
|
||||
typedef struct Tag_AccionFileNode {
|
||||
AccionFileCmp accion;
|
||||
FileNode *izquierda;
|
||||
FileNode *derecha;
|
||||
struct Tag_AccionFileNode *sig;
|
||||
typedef struct SAccionFileNode {
|
||||
AccionFileCmp action;
|
||||
FileNode *left;
|
||||
FileNode *right;
|
||||
struct SAccionFileNode *next;
|
||||
} AccionFileNode;
|
||||
|
||||
AccionFileNode *AccionFileNode_Crear();
|
||||
void AccionFileNode_Destruir(AccionFileNode *afn);
|
||||
AccionFileNode *AccionFileNode_CrearNormal(FileNode *fnIzq, FileNode *fnDer);
|
||||
AccionFileNode *AccionFileNode_Create();
|
||||
void AccionFileNode_Destroy(AccionFileNode *actionFileNode);
|
||||
AccionFileNode *AccionFileNode_CreateNormal(FileNode *fileNodeLeft,
|
||||
FileNode *fileNodeRight);
|
||||
|
||||
AccionFileNode *AccionFileNode_BuildSync(FileNode *izquierda,
|
||||
FileNode *derecha);
|
||||
AccionFileNode *AccionFileNode_BuildCopy(FileNode *izquierda,
|
||||
FileNode *derecha);
|
||||
AccionFileNode *AccionFileNode_BuildSync(FileNode *fileNodeLeft,
|
||||
FileNode *fileNodeRight);
|
||||
AccionFileNode *AccionFileNode_BuildCopy(FileNode *fileNodeLeft,
|
||||
FileNode *fileNodeRight);
|
||||
|
||||
void AccionFileNode_Print(AccionFileNode *afn);
|
||||
void AccionFileNode_Print(AccionFileNode *actionFileNode);
|
||||
|
||||
void AccionFileNode_RunList(AccionFileNode *afn, char *pathIzquierda,
|
||||
char *pathDerecha);
|
||||
void AccionFileNode_RunList(AccionFileNode *actionFileNode, char *pathLeft,
|
||||
char *pathRight);
|
||||
|
||||
#endif
|
||||
|
||||
73
fileutil.c
73
fileutil.c
@@ -19,12 +19,12 @@
|
||||
#include "fileutil.h"
|
||||
|
||||
#ifdef WIN32
|
||||
long long FileTime_to_POSIX(FILETIME ft) {
|
||||
long long FileTime_to_POSIX(FILETIME fileTime) {
|
||||
LARGE_INTEGER date, adjust;
|
||||
|
||||
// takes the last modified date
|
||||
date.HighPart = ft.dwHighDateTime;
|
||||
date.LowPart = ft.dwLowDateTime;
|
||||
date.HighPart = fileTime.dwHighDateTime;
|
||||
date.LowPart = fileTime.dwLowDateTime;
|
||||
|
||||
// 100-nanoseconds = milliseconds * 10000
|
||||
adjust.QuadPart = 11644473600000ll * 10000;
|
||||
@@ -36,12 +36,12 @@ long long FileTime_to_POSIX(FILETIME ft) {
|
||||
return date.QuadPart / 10000000ll;
|
||||
}
|
||||
|
||||
FILETIME POSIX_to_FileTime(FileTime ft) {
|
||||
FILETIME POSIX_to_FileTime(FileTime fileTime) {
|
||||
LARGE_INTEGER date, adjust;
|
||||
FILETIME filetime;
|
||||
FILETIME fileTimeOut;
|
||||
|
||||
// converts to 100-nanoseconds from seconds
|
||||
date.QuadPart=ft*10000000ll;
|
||||
date.QuadPart = fileTime * 10000000ll;
|
||||
|
||||
// 100-nanoseconds = milliseconds * 10000
|
||||
adjust.QuadPart = 11644473600000ll * 10000ll;
|
||||
@@ -50,27 +50,27 @@ FILETIME POSIX_to_FileTime(FileTime ft) {
|
||||
date.QuadPart += adjust.QuadPart;
|
||||
|
||||
// asigns to filetime
|
||||
filetime.dwHighDateTime=date.HighPart;
|
||||
filetime.dwLowDateTime=date.LowPart;
|
||||
return filetime;
|
||||
fileTimeOut.dwHighDateTime = date.HighPart;
|
||||
fileTimeOut.dwLowDateTime = date.LowPart;
|
||||
return fileTimeOut;
|
||||
}
|
||||
|
||||
FileTime FileTime_Get(char *filename) {
|
||||
FileTime FileTime_Get(char *fileName) {
|
||||
HANDLE hFile;
|
||||
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 );
|
||||
GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite);
|
||||
CloseHandle(hFile);
|
||||
return (FileTime_to_POSIX(ftWrite));
|
||||
}
|
||||
|
||||
void FileTime_Set(char *filename,FileTime t) {
|
||||
void FileTime_Set(char *fileName, FileTime fileTime) {
|
||||
HANDLE hFile;
|
||||
FILETIME ftWrite;
|
||||
hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE,
|
||||
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
|
||||
ftWrite=POSIX_to_FileTime(t);
|
||||
hFile = CreateFile(fileName, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
|
||||
ftWrite = POSIX_to_FileTime(fileTime);
|
||||
SetFileTime(hFile, NULL, NULL, &ftWrite);
|
||||
CloseHandle(hFile);
|
||||
}
|
||||
@@ -93,10 +93,10 @@ void FileTime_Set(char *filename, FileTime t) {
|
||||
|
||||
#endif
|
||||
|
||||
void FileTime_Print(FileTime t) {
|
||||
void FileTime_Print(FileTime fileTime) {
|
||||
struct tm *tms;
|
||||
|
||||
tms = localtime((time_t *) &t);
|
||||
tms = localtime((time_t *) &fileTime);
|
||||
printf("%04d-%02d-%02d %02d:%02d:%02d", tms->tm_year + 1900,
|
||||
tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min,
|
||||
tms->tm_sec);
|
||||
@@ -128,7 +128,7 @@ void File_GetName(char *path, char *name) {
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
int File_ExistePath(char *path) {
|
||||
int File_ExistsPath(char *path) {
|
||||
unsigned rc;
|
||||
rc = GetFileAttributes(path);
|
||||
|
||||
@@ -137,7 +137,7 @@ int File_ExistePath(char *path) {
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
int File_EsDirectorio(char *dir) {
|
||||
int File_IsDirectory(char *dir) {
|
||||
unsigned rc;
|
||||
rc = GetFileAttributes(dir);
|
||||
|
||||
@@ -149,7 +149,7 @@ int File_EsDirectorio(char *dir) {
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
int File_EsFichero(char *fichero) {
|
||||
int File_IsFile(char *fichero) {
|
||||
unsigned rc;
|
||||
rc = GetFileAttributes(fichero);
|
||||
|
||||
@@ -163,7 +163,7 @@ int File_EsFichero(char *fichero) {
|
||||
}
|
||||
|
||||
#else
|
||||
int File_ExistePath(char *path) {
|
||||
int File_ExistsPath(char *path) {
|
||||
struct stat info;
|
||||
|
||||
if (lstat(path, &info) == -1) {
|
||||
@@ -171,7 +171,7 @@ int File_ExistePath(char *path) {
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
int File_EsDirectorio(char *dir) {
|
||||
int File_IsDirectory(char *dir) {
|
||||
struct stat info;
|
||||
|
||||
if (lstat(dir, &info) == -1) {
|
||||
@@ -182,7 +182,7 @@ int File_EsDirectorio(char *dir) {
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
int File_EsFichero(char *fichero) {
|
||||
int File_IsFile(char *fichero) {
|
||||
struct stat info;
|
||||
|
||||
if (lstat(fichero, &info) == -1) {
|
||||
@@ -195,11 +195,11 @@ int File_EsFichero(char *fichero) {
|
||||
}
|
||||
#endif
|
||||
|
||||
long long File_TamanhoFichero(char *fichero) {
|
||||
long long File_GetSize(char *file) {
|
||||
FILE *f;
|
||||
long long tamanho;
|
||||
|
||||
f = fopen(fichero, "rb");
|
||||
f = fopen(file, "rb");
|
||||
if (!f)
|
||||
return (-1);
|
||||
|
||||
@@ -210,11 +210,11 @@ long long File_TamanhoFichero(char *fichero) {
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
int File_CrearDir(char *path) {
|
||||
int File_MakeDirectory(char *path) {
|
||||
return (_mkdir(path));
|
||||
}
|
||||
#else
|
||||
int File_CrearDir(char *path) {
|
||||
int File_MakeDirectory(char *path) {
|
||||
return (mkdir(path, 0777));
|
||||
}
|
||||
#endif
|
||||
@@ -222,8 +222,7 @@ int File_CrearDir(char *path) {
|
||||
#ifdef WIN32
|
||||
|
||||
void File_IterateDir(char *path,
|
||||
int (*func)(char *path,char *name,void *data),void *data)
|
||||
{
|
||||
int (*func)(char *path, char *name, void *data), void *data) {
|
||||
int handle;
|
||||
struct _finddata_t fileinfo;
|
||||
char f_path[MaxPath];
|
||||
@@ -232,21 +231,17 @@ void File_IterateDir(char *path,
|
||||
char path_aux[MaxPath];
|
||||
char *ptr;
|
||||
|
||||
snprintf(path_aux,MaxPath,
|
||||
"%s/*",path);
|
||||
snprintf(path_aux, MaxPath, "%s/*", path);
|
||||
handle = _findfirst(path_aux, &fileinfo);
|
||||
if (handle == -1)
|
||||
return;
|
||||
|
||||
// Recorrer el directorio
|
||||
do {
|
||||
if(strcmp(fileinfo.name,".") &&
|
||||
strcmp(fileinfo.name,".."))
|
||||
{
|
||||
if (strcmp(fileinfo.name, ".") && strcmp(fileinfo.name, "..")) {
|
||||
// A partir de aqui hay un fichero
|
||||
// (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);
|
||||
}
|
||||
findnext_rc = _findnext(handle, &fileinfo);
|
||||
@@ -285,16 +280,16 @@ void File_IterateDir(char *path,
|
||||
}
|
||||
#endif
|
||||
|
||||
void File_Borrar(char *path) {
|
||||
void File_Delete(char *path) {
|
||||
unlink(path);
|
||||
}
|
||||
|
||||
void File_BorrarDirectorio(char *path) {
|
||||
void File_DeleteDirectory(char *path) {
|
||||
rmdir(path);
|
||||
}
|
||||
|
||||
#define MaxBuffer 16384
|
||||
int File_Copiar(const char *pathOrig, const char *pathDest) {
|
||||
int File_Copy(const char *pathOrig, const char *pathDest) {
|
||||
FILE *fOrig, *fDest;
|
||||
char buffer[MaxBuffer];
|
||||
int readLen = 0;
|
||||
|
||||
16
fileutil.h
16
fileutil.h
@@ -17,20 +17,22 @@ void FileTime_Print(FileTime t);
|
||||
|
||||
void File_GetName(char *path, char *name);
|
||||
|
||||
int File_ExistePath(char *path);
|
||||
int File_ExistsPath(char *path);
|
||||
|
||||
int File_EsDirectorio(char *path);
|
||||
int File_IsDirectory(char *path);
|
||||
|
||||
int File_EsFichero(char *path);
|
||||
int File_IsFile(char *path);
|
||||
|
||||
long long File_TamanhoFichero(char *ficheros);
|
||||
long long File_GetSize(char *ficheros);
|
||||
|
||||
int File_CrearDir(char *path);
|
||||
int File_MakeDirectory(char *path);
|
||||
|
||||
void File_IterateDir(char *path,
|
||||
int (*func)(char *path, char *name, void *data), void *data);
|
||||
|
||||
void File_Borrar(char *path);
|
||||
void File_BorrarDirectorio(char *path);
|
||||
void File_Delete(char *path);
|
||||
void File_DeleteDirectory(char *path);
|
||||
|
||||
int File_Copy(const char *pathOrig, const char *pathDest);
|
||||
|
||||
#endif
|
||||
|
||||
210
main.c
210
main.c
@@ -8,10 +8,10 @@
|
||||
#include "filenode.h"
|
||||
#include "filenodecmp.h"
|
||||
|
||||
void help(char *exe) {
|
||||
void Help(char *exe) {
|
||||
char exeFilename[MaxPath];
|
||||
File_GetName(exe, exeFilename);
|
||||
printf("Modo de uso:\n");
|
||||
printf("Usage:\n");
|
||||
printf(" %s info [file] {[file] {..}}\n", exeFilename);
|
||||
printf(" %s scan [dir] [tree] \n", exeFilename);
|
||||
printf(" %s rescan [dir] [tree] \n", exeFilename);
|
||||
@@ -29,214 +29,190 @@ void help(char *exe) {
|
||||
printf(" %s recopytest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
}
|
||||
|
||||
FileNode *checkDir(char *path, int recheck);
|
||||
int sync(char *pathIzquierda, char *pathDerecha, int recheck, int dryrun);
|
||||
FileNode *CheckDir(char *path, int recheck);
|
||||
int Sync(char *pathLeft, char *pathRight, int recheck, int dryRun);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
FILE *f;
|
||||
FILE *file;
|
||||
unsigned long crc = 0;
|
||||
FileTime ft;
|
||||
FileTime fileTime;
|
||||
int i;
|
||||
|
||||
if (argc < 2) {
|
||||
help(argv[0]);
|
||||
Help(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[1], "info") && argc >= 3) {
|
||||
// Informacion de ficheros
|
||||
for (i = 2; i < argc; i++) {
|
||||
if (File_ExistePath(argv[i])) {
|
||||
f = fopen(argv[i], "rb");
|
||||
if (f) {
|
||||
crc = CRC_File(f);
|
||||
fclose(f);
|
||||
if (File_ExistsPath(argv[i])) {
|
||||
file = fopen(argv[i], "rb");
|
||||
if (file) {
|
||||
crc = CRC_File(file);
|
||||
fclose(file);
|
||||
}
|
||||
ft = FileTime_Get(argv[i]);
|
||||
fileTime = FileTime_Get(argv[i]);
|
||||
printf("%s:\t[%08X]\t", argv[i], crc);
|
||||
FileTime_Print(ft);
|
||||
FileTime_Print(fileTime);
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(argv[1], "scan") && argc == 4) {
|
||||
// Scanear informacion de directorio y guardar arbol
|
||||
FileNode *fn;
|
||||
FileNode *fileNode;
|
||||
printf("Building FileNode..\n");
|
||||
fn = FileNode_Build(argv[2]);
|
||||
FileNode_Save(fn, argv[3]);
|
||||
fileNode = FileNode_Build(argv[2]);
|
||||
FileNode_Save(fileNode, argv[3]);
|
||||
} else if (!strcmp(argv[1], "rescan") && argc == 4) {
|
||||
// Scanear informacion de directorio y guardar arbol
|
||||
FileNode *fn;
|
||||
FileNode *fileNode;
|
||||
printf("Loading FileNode..\n");
|
||||
fn = FileNode_Load(argv[3]);
|
||||
if (fn) {
|
||||
fileNode = FileNode_Load(argv[3]);
|
||||
if (fileNode) {
|
||||
printf("Rebuilding FileNode..\n");
|
||||
fn = FileNode_Refresh(fn, argv[2]);
|
||||
FileNode_Save(fn, argv[3]);
|
||||
fileNode = FileNode_Refresh(fileNode, argv[2]);
|
||||
FileNode_Save(fileNode, argv[3]);
|
||||
}
|
||||
} else if (!strcmp(argv[1], "read") && argc == 3) {
|
||||
// Leer informacion de arbol
|
||||
FileNode *fn;
|
||||
fn = FileNode_Load(argv[2]);
|
||||
if (fn)
|
||||
FileNode_Print(fn);
|
||||
FileNode *fileNode;
|
||||
fileNode = FileNode_Load(argv[2]);
|
||||
if (fileNode)
|
||||
FileNode_Print(fileNode);
|
||||
} else if (!strcmp(argv[1], "dir") && argc == 3) {
|
||||
// Leer informacion de dir
|
||||
char *path = argv[2];
|
||||
char dirNodesFile[MaxPath];
|
||||
FileNode *fn;
|
||||
FileNode *fileNode;
|
||||
|
||||
fn = checkDir(path, 1);
|
||||
if (fn) {
|
||||
FileNode_Print(fn);
|
||||
fileNode = CheckDir(path, 1);
|
||||
if (fileNode) {
|
||||
FileNode_Print(fileNode);
|
||||
}
|
||||
} else if (argc == 4) {
|
||||
char *cmd = argv[1];
|
||||
char *pathLeft = argv[2];
|
||||
char *pathRight = argv[3];
|
||||
if (!strcmp(cmd, "sync")) {
|
||||
Sync(pathLeft, pathRight, 1, 0);
|
||||
} else if (!strcmp(cmd, "resync")) {
|
||||
Sync(pathLeft, pathRight, 0, 0);
|
||||
} else if (!strcmp(cmd, "synctest")) {
|
||||
Sync(pathLeft, pathRight, 1, 1);
|
||||
} else if (!strcmp(cmd, "resynctest")) {
|
||||
Sync(pathLeft, pathRight, 0, 1);
|
||||
} else if (!strcmp(cmd, "copy")) {
|
||||
Copy(pathLeft, pathRight, 1, 0);
|
||||
} else if (!strcmp(cmd, "recopy")) {
|
||||
Copy(pathLeft, pathRight, 0, 0);
|
||||
} else if (!strcmp(cmd, "copytest")) {
|
||||
Copy(pathLeft, pathRight, 1, 1);
|
||||
} else if (!strcmp(cmd, "recopytest")) {
|
||||
Copy(pathLeft, pathRight, 0, 1);
|
||||
}
|
||||
} else if (!strcmp(argv[1], "sync") && argc == 4) {
|
||||
// Sincronizar dos directorios
|
||||
char *pathIzquierda = argv[2];
|
||||
char *pathDerecha = argv[3];
|
||||
sync(pathIzquierda, pathDerecha, 1, 0);
|
||||
} else if (!strcmp(argv[1], "resync") && argc == 4) {
|
||||
// Sincronizar dos directorios
|
||||
char *pathIzquierda = argv[2];
|
||||
char *pathDerecha = argv[3];
|
||||
sync(pathIzquierda, pathDerecha, 0, 0);
|
||||
} else if (!strcmp(argv[1], "synctest") && argc == 4) {
|
||||
// Sincronizar dos directorios
|
||||
char *pathIzquierda = argv[2];
|
||||
char *pathDerecha = argv[3];
|
||||
sync(pathIzquierda, pathDerecha, 1, 1);
|
||||
} else if (!strcmp(argv[1], "resynctest") && argc == 4) {
|
||||
// Sincronizar dos directorios
|
||||
char *pathIzquierda = argv[2];
|
||||
char *pathDerecha = argv[3];
|
||||
sync(pathIzquierda, pathDerecha, 0, 1);
|
||||
|
||||
} else if (!strcmp(argv[1], "copy") && argc == 4) {
|
||||
// Sincronizar dos directorios
|
||||
char *pathIzquierda = argv[2];
|
||||
char *pathDerecha = argv[3];
|
||||
copy(pathIzquierda, pathDerecha, 1, 0);
|
||||
} else if (!strcmp(argv[1], "recopy") && argc == 4) {
|
||||
// Sincronizar dos directorios
|
||||
char *pathIzquierda = argv[2];
|
||||
char *pathDerecha = argv[3];
|
||||
copy(pathIzquierda, pathDerecha, 0, 0);
|
||||
} else if (!strcmp(argv[1], "copytest") && argc == 4) {
|
||||
// Sincronizar dos directorios
|
||||
char *pathIzquierda = argv[2];
|
||||
char *pathDerecha = argv[3];
|
||||
copy(pathIzquierda, pathDerecha, 1, 1);
|
||||
} else if (!strcmp(argv[1], "recopytest") && argc == 4) {
|
||||
// Sincronizar dos directorios
|
||||
char *pathIzquierda = argv[2];
|
||||
char *pathDerecha = argv[3];
|
||||
copy(pathIzquierda, pathDerecha, 0, 1);
|
||||
|
||||
} else {
|
||||
help(argv[0]);
|
||||
Help(argv[0]);
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
FileNode *checkDir(char *path, int recheck) {
|
||||
FileNode *CheckDir(char *path, int recheck) {
|
||||
char dirNodesFile[MaxPath];
|
||||
FileNode *fn;
|
||||
FileNode *fileNode;
|
||||
|
||||
// Comprobar directorio
|
||||
snprintf(dirNodesFile, MaxPath, "%s/"FileNode_Filename, path);
|
||||
if (recheck) {
|
||||
printf("Checking Directory.. %s\n", path);
|
||||
fn = FileNode_Load(dirNodesFile);
|
||||
if (fn) {
|
||||
fn = FileNode_Refresh(fn, path);
|
||||
fileNode = FileNode_Load(dirNodesFile);
|
||||
if (fileNode) {
|
||||
fileNode = FileNode_Refresh(fileNode, path);
|
||||
} else {
|
||||
fn = FileNode_Build(path);
|
||||
fileNode = FileNode_Build(path);
|
||||
}
|
||||
FileNode_Save(fn, dirNodesFile);
|
||||
FileNode_Save(fileNode, dirNodesFile);
|
||||
} else {
|
||||
printf("Loading Directory.. %s\n", path);
|
||||
fn = FileNode_Load(dirNodesFile);
|
||||
if (!fn) {
|
||||
fileNode = FileNode_Load(dirNodesFile);
|
||||
if (!fileNode) {
|
||||
printf("Error, no nodesFile.fs\n");
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
return fn;
|
||||
return fileNode;
|
||||
}
|
||||
|
||||
int sync(char *pathIzquierda, char *pathDerecha, int recheck, int dryrun) {
|
||||
char dirNodesFileIzq[MaxPath];
|
||||
char dirNodesFileDer[MaxPath];
|
||||
FileNode *fnIzquierda, *fnDerecha;
|
||||
int Sync(char *pathLeft, char *pathRight, int recheck, int dryRun) {
|
||||
FileNode *fileNodeLeft, *fileNodeRight;
|
||||
|
||||
// Comprobar y cargar directorios
|
||||
if (!File_ExistePath(pathIzquierda) || !File_EsDirectorio(pathIzquierda)) {
|
||||
printf("Error, directory does not exist: %s\n", pathIzquierda);
|
||||
if (!File_ExistsPath(pathLeft) || !File_IsDirectory(pathLeft)) {
|
||||
printf("Error, directory does not exist: %s\n", pathLeft);
|
||||
return 0;
|
||||
}
|
||||
if (!File_ExistePath(pathDerecha) || !File_EsDirectorio(pathDerecha)) {
|
||||
printf("Error, directory does not exist: %s\n", pathDerecha);
|
||||
if (!File_ExistsPath(pathRight) || !File_IsDirectory(pathRight)) {
|
||||
printf("Error, directory does not exist: %s\n", pathRight);
|
||||
return 0;
|
||||
}
|
||||
fnIzquierda = checkDir(pathIzquierda, recheck);
|
||||
if (!fnIzquierda) {
|
||||
fileNodeLeft = CheckDir(pathLeft, recheck);
|
||||
if (!fileNodeLeft) {
|
||||
return 0;
|
||||
}
|
||||
fnDerecha = checkDir(pathDerecha, recheck);
|
||||
if (!fnDerecha) {
|
||||
fileNodeRight = CheckDir(pathRight, recheck);
|
||||
if (!fileNodeRight) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Construir acciones
|
||||
printf("Building action list.. \n");
|
||||
AccionFileNode *afn = NULL;
|
||||
afn = AccionFileNode_BuildSync(fnIzquierda, fnDerecha);
|
||||
AccionFileNode *actionFileNode = NULL;
|
||||
actionFileNode = AccionFileNode_BuildSync(fileNodeLeft, fileNodeRight);
|
||||
|
||||
if (dryrun) {
|
||||
if (dryRun) {
|
||||
// Mostrar lista de acciones
|
||||
AccionFileNode_Print(afn);
|
||||
AccionFileNode_Print(actionFileNode);
|
||||
} else {
|
||||
// Ejecutar lista de acciones
|
||||
AccionFileNode_RunList(afn, pathIzquierda, pathDerecha);
|
||||
AccionFileNode_RunList(actionFileNode, pathLeft, pathRight);
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
int copy(char *pathIzquierda, char *pathDerecha, int recheck, int dryrun) {
|
||||
char dirNodesFileIzq[MaxPath];
|
||||
char dirNodesFileDer[MaxPath];
|
||||
FileNode *fnIzquierda, *fnDerecha;
|
||||
int Copy(char *pathLeft, char *pathRight, int reCheck, int dryRun) {
|
||||
FileNode *fileNodeLeft, *fileNodeRight;
|
||||
|
||||
// Comprobar y cargar directorios
|
||||
if (!File_ExistePath(pathIzquierda) || !File_EsDirectorio(pathIzquierda)) {
|
||||
printf("Error, directory does not exist: %s\n", pathIzquierda);
|
||||
if (!File_ExistsPath(pathLeft) || !File_IsDirectory(pathLeft)) {
|
||||
printf("Error, directory does not exist: %s\n", pathLeft);
|
||||
return 0;
|
||||
}
|
||||
if (!File_ExistePath(pathDerecha) || !File_EsDirectorio(pathDerecha)) {
|
||||
printf("Error, directory does not exist: %s\n", pathDerecha);
|
||||
if (!File_ExistsPath(pathRight) || !File_IsDirectory(pathRight)) {
|
||||
printf("Error, directory does not exist: %s\n", pathRight);
|
||||
return 0;
|
||||
}
|
||||
fnIzquierda = checkDir(pathIzquierda, recheck);
|
||||
if (!fnIzquierda) {
|
||||
fileNodeLeft = CheckDir(pathLeft, reCheck);
|
||||
if (!fileNodeLeft) {
|
||||
return 0;
|
||||
}
|
||||
fnDerecha = checkDir(pathDerecha, recheck);
|
||||
if (!fnDerecha) {
|
||||
fileNodeRight = CheckDir(pathRight, reCheck);
|
||||
if (!fileNodeRight) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Construir acciones
|
||||
printf("Building action list.. \n");
|
||||
AccionFileNode *afn = NULL;
|
||||
afn = AccionFileNode_BuildCopy(fnIzquierda, fnDerecha);
|
||||
AccionFileNode *actionFileNode = NULL;
|
||||
actionFileNode = AccionFileNode_BuildCopy(fileNodeLeft, fileNodeRight);
|
||||
|
||||
if (dryrun) {
|
||||
if (dryRun) {
|
||||
// Mostrar lista de acciones
|
||||
AccionFileNode_Print(afn);
|
||||
AccionFileNode_Print(actionFileNode);
|
||||
} else {
|
||||
// Ejecutar lista de acciones
|
||||
AccionFileNode_RunList(afn, pathIzquierda, pathDerecha);
|
||||
AccionFileNode_RunList(actionFileNode, pathLeft, pathRight);
|
||||
}
|
||||
|
||||
return (1);
|
||||
|
||||
Reference in New Issue
Block a user