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