Code formating
This commit is contained in:
2
crc.c
2
crc.c
@@ -27,7 +27,6 @@ void CRCTable_Init(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long CRC_Buffer(unsigned char *buffer, int len, unsigned long crc) {
|
unsigned long CRC_Buffer(unsigned char *buffer, int len, unsigned long crc) {
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
unsigned long temp1;
|
unsigned long temp1;
|
||||||
@@ -44,7 +43,6 @@ unsigned long CRC_Buffer(unsigned char *buffer,int len,unsigned long crc){
|
|||||||
return (crc);
|
return (crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned long CRC_File(FILE *file) {
|
unsigned long CRC_File(FILE *file) {
|
||||||
unsigned long crc;
|
unsigned long crc;
|
||||||
int count;
|
int count;
|
||||||
|
|||||||
85
filenode.c
85
filenode.c
@@ -7,8 +7,6 @@
|
|||||||
#include "fileutil.h"
|
#include "fileutil.h"
|
||||||
#include "filenode.h"
|
#include "filenode.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
FileNode *_free_filenode = NULL;
|
FileNode *_free_filenode = NULL;
|
||||||
int _n_filenode = 0;
|
int _n_filenode = 0;
|
||||||
#define FileNode_Tocho 1024
|
#define FileNode_Tocho 1024
|
||||||
@@ -62,7 +60,6 @@ void FileNode_AddChild(FileNode *file,FileNode *file2){
|
|||||||
file2->padre = file;
|
file2->padre = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileNode_SetEstadoRec(FileNode *file, EstadoFichero estado) {
|
void FileNode_SetEstadoRec(FileNode *file, EstadoFichero estado) {
|
||||||
FileNode *fn_child;
|
FileNode *fn_child;
|
||||||
file->estado = estado;
|
file->estado = estado;
|
||||||
@@ -86,10 +83,14 @@ char *FileNode_GetPath(FileNode *fn,char *path){
|
|||||||
char *pathnodes[128];
|
char *pathnodes[128];
|
||||||
int levels, i;
|
int levels, i;
|
||||||
char *pathptr = temppath;
|
char *pathptr = temppath;
|
||||||
if(path)pathptr=path;
|
if (path)
|
||||||
|
pathptr = path;
|
||||||
|
|
||||||
FileNode_GetPath_Rec(fn, pathnodes);
|
FileNode_GetPath_Rec(fn, pathnodes);
|
||||||
levels=0;while(pathnodes[levels]){levels++;}
|
levels = 0;
|
||||||
|
while (pathnodes[levels]) {
|
||||||
|
levels++;
|
||||||
|
}
|
||||||
strcpy(pathptr, "");
|
strcpy(pathptr, "");
|
||||||
for (i = levels - 1; i >= 0; i--) {
|
for (i = levels - 1; i >= 0; i--) {
|
||||||
strcat(pathptr, pathnodes[i]);
|
strcat(pathptr, pathnodes[i]);
|
||||||
@@ -102,10 +103,14 @@ char *FileNode_GetFullPath(FileNode *fn,char *basePath,char *path){
|
|||||||
char *pathnodes[128];
|
char *pathnodes[128];
|
||||||
int levels, i;
|
int levels, i;
|
||||||
char *pathptr = temppath;
|
char *pathptr = temppath;
|
||||||
if(path)pathptr=path;
|
if (path)
|
||||||
|
pathptr = path;
|
||||||
|
|
||||||
FileNode_GetPath_Rec(fn, pathnodes);
|
FileNode_GetPath_Rec(fn, pathnodes);
|
||||||
levels=0;while(pathnodes[levels]){levels++;}
|
levels = 0;
|
||||||
|
while (pathnodes[levels]) {
|
||||||
|
levels++;
|
||||||
|
}
|
||||||
strcpy(pathptr, basePath);
|
strcpy(pathptr, basePath);
|
||||||
strcat(pathptr, "/");
|
strcat(pathptr, "/");
|
||||||
for (i = levels - 2; i >= 0; i--) {
|
for (i = levels - 2; i >= 0; i--) {
|
||||||
@@ -116,8 +121,6 @@ char *FileNode_GetFullPath(FileNode *fn,char *basePath,char *path){
|
|||||||
return temppath;
|
return temppath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void FileNode_GetTamanho(FileNode *fn, char *file) {
|
void FileNode_GetTamanho(FileNode *fn, char *file) {
|
||||||
fn->flags |= FileFlag_TieneTamanho;
|
fn->flags |= FileFlag_TieneTamanho;
|
||||||
fn->size = File_TamanhoFichero(file);
|
fn->size = File_TamanhoFichero(file);
|
||||||
@@ -131,18 +134,14 @@ void FileNode_GetFecha(FileNode *fn,char *file){
|
|||||||
void FileNode_GetCRC(FileNode *fn, char *file) {
|
void FileNode_GetCRC(FileNode *fn, char *file) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
f = fopen(file, "rb");
|
f = fopen(file, "rb");
|
||||||
if(!f){ return; }
|
if (!f) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
fn->flags |= FileFlag_TieneCRC;
|
fn->flags |= FileFlag_TieneCRC;
|
||||||
fn->crc = CRC_File(f);
|
fn->crc = CRC_File(f);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void FileNode_SaveNode(FileNode *fn, FILE *file) {
|
void FileNode_SaveNode(FileNode *fn, FILE *file) {
|
||||||
short name_len;
|
short name_len;
|
||||||
|
|
||||||
@@ -201,12 +200,10 @@ 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(fn, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileNode *FileNode_LoadNode(FILE *file) {
|
FileNode *FileNode_LoadNode(FILE *file) {
|
||||||
short name_len;
|
short name_len;
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
@@ -259,7 +256,6 @@ FileNode *FileNode_LoadNode(FILE *file){
|
|||||||
return (fn);
|
return (fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FileNode *FileNode_Load(char *fichero) {
|
FileNode *FileNode_Load(char *fichero) {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
@@ -285,14 +281,12 @@ FileNode *FileNode_Load(char *fichero){
|
|||||||
return (NULL );
|
return (NULL );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn = FileNode_LoadNode(file);
|
fn = FileNode_LoadNode(file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
return (fn);
|
return (fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileNode_PrintNode(FileNode *fn) {
|
void FileNode_PrintNode(FileNode *fn) {
|
||||||
printf(FileNode_GetPath(fn, NULL ));
|
printf(FileNode_GetPath(fn, NULL ));
|
||||||
if (fn->flags & FileFlag_Normal) {
|
if (fn->flags & FileFlag_Normal) {
|
||||||
@@ -330,7 +324,6 @@ void FileNode_PrintNode(FileNode *fn){
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileNode_Print(FileNode *fn) {
|
void FileNode_Print(FileNode *fn) {
|
||||||
FileNode *fnAux = fn;
|
FileNode *fnAux = fn;
|
||||||
int end = 0;
|
int end = 0;
|
||||||
@@ -359,21 +352,6 @@ 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) {
|
||||||
@@ -402,9 +380,9 @@ FileNode *FileNode_Build(char *path){
|
|||||||
return (file);
|
return (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 *file, *fn_padre = d;
|
||||||
|
;
|
||||||
|
|
||||||
if (!strcmp(name, FileNode_Filename)) {
|
if (!strcmp(name, FileNode_Filename)) {
|
||||||
return (0);
|
return (0);
|
||||||
@@ -416,20 +394,6 @@ int FileNode_Build_Iterate(char *path,char *name,void *d){
|
|||||||
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 *fn, char *path) {
|
||||||
@@ -473,7 +437,8 @@ FileNode *FileNode_Refresh(FileNode *fn,char *path){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Marcar hijos para determinar cual es actualizado
|
// Marcar hijos para determinar cual es actualizado
|
||||||
fn_child=fn->child;while(fn_child){
|
fn_child = fn->child;
|
||||||
|
while (fn_child) {
|
||||||
fn_child->flags |= FileFlag_MarcaRevision;
|
fn_child->flags |= FileFlag_MarcaRevision;
|
||||||
fn_child = fn_child->sig;
|
fn_child = fn_child->sig;
|
||||||
}
|
}
|
||||||
@@ -482,7 +447,8 @@ FileNode *FileNode_Refresh(FileNode *fn,char *path){
|
|||||||
File_IterateDir(path, FileNode_Refresh_Iterate, fn);
|
File_IterateDir(path, FileNode_Refresh_Iterate, fn);
|
||||||
|
|
||||||
// Buscar que sigan marcados (borrados)
|
// Buscar que sigan marcados (borrados)
|
||||||
fn_child=fn->child;while(fn_child){
|
fn_child = fn->child;
|
||||||
|
while (fn_child) {
|
||||||
if (fn_child->flags & FileFlag_MarcaRevision) {
|
if (fn_child->flags & FileFlag_MarcaRevision) {
|
||||||
fn_child->flags &= ~FileFlag_MarcaRevision;
|
fn_child->flags &= ~FileFlag_MarcaRevision;
|
||||||
FileNode_SetEstadoRec(fn_child, EstadoFichero_Borrado);
|
FileNode_SetEstadoRec(fn_child, EstadoFichero_Borrado);
|
||||||
@@ -542,12 +508,3 @@ int FileNode_Refresh_Iterate(char *path,char *name,void *d){
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -56,10 +56,8 @@ FileNode *FileNode_Load(char *fichero);
|
|||||||
void FileNode_PrintNode(FileNode *fn);
|
void FileNode_PrintNode(FileNode *fn);
|
||||||
void FileNode_Print(FileNode *fn);
|
void FileNode_Print(FileNode *fn);
|
||||||
|
|
||||||
|
|
||||||
FileNode *FileNode_Build(char *path);
|
FileNode *FileNode_Build(char *path);
|
||||||
|
|
||||||
FileNode *FileNode_Refresh(FileNode *file, char *path);
|
FileNode *FileNode_Refresh(FileNode *file, char *path);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
162
filenodecmp.c
162
filenodecmp.c
@@ -40,15 +40,13 @@ AccionFileNode *AccionFileNode_Crear(){
|
|||||||
return (afn);
|
return (afn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AccionFileNode_Destruir(AccionFileNode *afn) {
|
void AccionFileNode_Destruir(AccionFileNode *afn) {
|
||||||
afn->sig = _free_accionfilenode;
|
afn->sig = _free_accionfilenode;
|
||||||
_free_accionfilenode = afn;
|
_free_accionfilenode = afn;
|
||||||
_n_accionfilenode--;
|
_n_accionfilenode--;
|
||||||
}
|
}
|
||||||
|
|
||||||
AccionFileNode *AccionFileNode_CrearNormal(FileNode *fnIzq,FileNode *fnDer)
|
AccionFileNode *AccionFileNode_CrearNormal(FileNode *fnIzq, FileNode *fnDer) {
|
||||||
{
|
|
||||||
AccionFileNode *afnNew;
|
AccionFileNode *afnNew;
|
||||||
afnNew = AccionFileNode_Crear();
|
afnNew = AccionFileNode_Crear();
|
||||||
afnNew->accion = AccionFileCmp_Nada;
|
afnNew->accion = AccionFileCmp_Nada;
|
||||||
@@ -57,11 +55,10 @@ AccionFileNode *AccionFileNode_CrearNormal(FileNode *fnIzq,FileNode *fnDer)
|
|||||||
return afnNew;
|
return afnNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccionFileNode_CompareChilds(
|
void AccionFileNode_CompareChilds(AccionFileNode *afnRaiz,
|
||||||
AccionFileNode *afnRaiz,
|
|
||||||
AccionFileNode **afnCola,
|
AccionFileNode **afnCola,
|
||||||
void (*CheckPair)(FileNode *fnIzq,FileNode *fnDer,AccionFileNode **afnCola))
|
void (*CheckPair)(FileNode *fnIzq, FileNode *fnDer,
|
||||||
{
|
AccionFileNode **afnCola)) {
|
||||||
FileNode *fnIzq, *fnDer;
|
FileNode *fnIzq, *fnDer;
|
||||||
AccionFileNode *afnColaStart = (*afnCola);
|
AccionFileNode *afnColaStart = (*afnCola);
|
||||||
|
|
||||||
@@ -94,7 +91,6 @@ void AccionFileNode_CompareChilds(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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 (afnRaiz->derecha) {
|
||||||
@@ -106,7 +102,8 @@ void AccionFileNode_CompareChilds(
|
|||||||
while (fnIzq) {
|
while (fnIzq) {
|
||||||
AccionFileNode *afnCheck = afnColaStart;
|
AccionFileNode *afnCheck = afnColaStart;
|
||||||
while (afnCheck) {
|
while (afnCheck) {
|
||||||
if(afnCheck->izquierda==fnIzq && afnCheck->derecha==fnDer){
|
if (afnCheck->izquierda == fnIzq
|
||||||
|
&& afnCheck->derecha == fnDer) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
afnCheck = afnCheck->sig;
|
afnCheck = afnCheck->sig;
|
||||||
@@ -137,11 +134,8 @@ void AccionFileNode_CompareChilds(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AccionFileNode_DeletePair(FileNode *fnIzq, FileNode *fnDer,
|
||||||
|
AccionFileNode **afnCola) {
|
||||||
void AccionFileNode_DeletePair(
|
|
||||||
FileNode *fnIzq,FileNode *fnDer,AccionFileNode **afnCola)
|
|
||||||
{
|
|
||||||
AccionFileNode *afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
AccionFileNode *afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
||||||
|
|
||||||
if (!fnIzq && !fnDer) {
|
if (!fnIzq && !fnDer) {
|
||||||
@@ -181,9 +175,8 @@ void AccionFileNode_DeletePair(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fnIzq && fnDer) {
|
if (fnIzq && fnDer) {
|
||||||
if(fnIzq->flags&FileFlag_Directorio ||
|
if ((fnIzq->flags & FileFlag_Directorio)
|
||||||
fnDer->flags&FileFlag_Directorio)
|
|| (fnDer->flags & FileFlag_Directorio)) {
|
||||||
{
|
|
||||||
// Alguno es directorio
|
// Alguno es directorio
|
||||||
|
|
||||||
// Iterar hijos para borrarlos
|
// Iterar hijos para borrarlos
|
||||||
@@ -199,7 +192,9 @@ void AccionFileNode_DeletePair(
|
|||||||
afnNew = NULL;
|
afnNew = NULL;
|
||||||
}
|
}
|
||||||
if (fnDer->estado != EstadoFichero_Borrado) {
|
if (fnDer->estado != EstadoFichero_Borrado) {
|
||||||
if(!afnNew){ afnNew=AccionFileNode_CrearNormal(fnIzq,fnDer); }
|
if (!afnNew) {
|
||||||
|
afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
||||||
|
}
|
||||||
// Accion de borrado para el nodo derecho
|
// Accion de borrado para el nodo derecho
|
||||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||||
(*afnCola)->sig = afnNew;
|
(*afnCola)->sig = afnNew;
|
||||||
@@ -212,9 +207,8 @@ void AccionFileNode_DeletePair(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccionFileNode_CheckPair(
|
void AccionFileNode_CheckPair(FileNode *fnIzq, FileNode *fnDer,
|
||||||
FileNode *fnIzq,FileNode *fnDer,AccionFileNode **afnCola)
|
AccionFileNode **afnCola) {
|
||||||
{
|
|
||||||
AccionFileNode *afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
AccionFileNode *afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
||||||
|
|
||||||
if (!fnIzq && !fnDer) {
|
if (!fnIzq && !fnDer) {
|
||||||
@@ -298,25 +292,21 @@ void AccionFileNode_CheckPair(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fnIzq && fnDer) {
|
if (fnIzq && fnDer) {
|
||||||
if(fnIzq->flags&FileFlag_Directorio &&
|
if ((fnIzq->flags & FileFlag_Directorio)
|
||||||
fnDer->flags&FileFlag_Directorio)
|
&& (fnDer->flags & FileFlag_Directorio)) {
|
||||||
{
|
|
||||||
// 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->ft - fnDer->ft) <= 1) { // appoximadamente iguales
|
||||||
if(fnDer->estado==EstadoFichero_Borrado &&
|
if (fnDer->estado == EstadoFichero_Borrado
|
||||||
fnIzq->estado==EstadoFichero_Borrado)
|
&& fnIzq->estado == EstadoFichero_Borrado) {
|
||||||
{
|
|
||||||
afnNew->accion = AccionFileCmp_Nada;
|
afnNew->accion = AccionFileCmp_Nada;
|
||||||
}else
|
} else if (fnDer->estado == EstadoFichero_Borrado) {
|
||||||
if(fnDer->estado==EstadoFichero_Borrado){
|
|
||||||
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
||||||
if (fnIzq->estado == EstadoFichero_Borrado) {
|
if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||||
afnNew->accion = AccionFileCmp_Nada;
|
afnNew->accion = AccionFileCmp_Nada;
|
||||||
}
|
}
|
||||||
}else
|
} else if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||||
if(fnIzq->estado==EstadoFichero_Borrado){
|
|
||||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||||
if (fnDer->estado == EstadoFichero_Borrado) {
|
if (fnDer->estado == EstadoFichero_Borrado) {
|
||||||
afnNew->accion = AccionFileCmp_Nada;
|
afnNew->accion = AccionFileCmp_Nada;
|
||||||
@@ -324,8 +314,7 @@ void AccionFileNode_CheckPair(
|
|||||||
} else {
|
} else {
|
||||||
afnNew->accion = AccionFileCmp_Nada;
|
afnNew->accion = AccionFileCmp_Nada;
|
||||||
}
|
}
|
||||||
}else
|
} else if (fnIzq->ft < fnDer->ft) {
|
||||||
if(fnIzq->ft<fnDer->ft){
|
|
||||||
afnNew->accion = AccionFileCmp_FechaDerechaAIzquierda;
|
afnNew->accion = AccionFileCmp_FechaDerechaAIzquierda;
|
||||||
if (fnDer->estado == EstadoFichero_Borrado) {
|
if (fnDer->estado == EstadoFichero_Borrado) {
|
||||||
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
||||||
@@ -333,8 +322,7 @@ void AccionFileNode_CheckPair(
|
|||||||
afnNew->accion = AccionFileCmp_Nada;
|
afnNew->accion = AccionFileCmp_Nada;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else
|
} else if (fnIzq->ft > fnDer->ft) {
|
||||||
if(fnIzq->ft>fnDer->ft){
|
|
||||||
afnNew->accion = AccionFileCmp_FechaIzquierdaADerecha;
|
afnNew->accion = AccionFileCmp_FechaIzquierdaADerecha;
|
||||||
if (fnIzq->estado == EstadoFichero_Borrado) {
|
if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||||
@@ -345,11 +333,10 @@ void AccionFileNode_CheckPair(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Procesar nodos hijos
|
// Procesar nodos hijos
|
||||||
if(afnNew->accion==AccionFileCmp_BorrarDerecha ||
|
if (afnNew->accion == AccionFileCmp_BorrarDerecha
|
||||||
afnNew->accion==AccionFileCmp_BorrarIzquierda ||
|
|| afnNew->accion == AccionFileCmp_BorrarIzquierda
|
||||||
(fnIzq->estado==EstadoFichero_Borrado &&
|
|| (fnIzq->estado == EstadoFichero_Borrado
|
||||||
fnDer->estado==EstadoFichero_Borrado))
|
&& fnDer->estado == EstadoFichero_Borrado)) {
|
||||||
{
|
|
||||||
// Iterar nodos hijos para borrarlos
|
// Iterar nodos hijos para borrarlos
|
||||||
AccionFileNode_CompareChilds(afnNew, afnCola,
|
AccionFileNode_CompareChilds(afnNew, afnCola,
|
||||||
AccionFileNode_DeletePair);
|
AccionFileNode_DeletePair);
|
||||||
@@ -362,27 +349,21 @@ void AccionFileNode_CheckPair(
|
|||||||
(*afnCola)->sig = afnNew;
|
(*afnCola)->sig = afnNew;
|
||||||
(*afnCola) = afnNew;
|
(*afnCola) = afnNew;
|
||||||
|
|
||||||
}else
|
} else if ((fnIzq->flags & FileFlag_Normal)
|
||||||
if(fnIzq->flags&FileFlag_Normal &&
|
&& (fnDer->flags & FileFlag_Normal)) {
|
||||||
fnDer->flags&FileFlag_Normal)
|
|
||||||
{
|
|
||||||
// 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->ft - fnDer->ft) <= 1) { // appoximadamente iguales
|
||||||
if(fnDer->estado==EstadoFichero_Borrado &&
|
if (fnDer->estado == EstadoFichero_Borrado
|
||||||
fnIzq->estado==EstadoFichero_Borrado)
|
&& fnIzq->estado == EstadoFichero_Borrado) {
|
||||||
{
|
|
||||||
afnNew->accion = AccionFileCmp_Nada;
|
afnNew->accion = AccionFileCmp_Nada;
|
||||||
}else
|
} else if (fnDer->estado == EstadoFichero_Borrado) {
|
||||||
if(fnDer->estado==EstadoFichero_Borrado){
|
|
||||||
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
||||||
if (fnIzq->estado == EstadoFichero_Borrado) {
|
if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||||
afnNew->accion = AccionFileCmp_Nada;
|
afnNew->accion = AccionFileCmp_Nada;
|
||||||
}
|
}
|
||||||
}else
|
} else if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||||
if(fnIzq->estado==EstadoFichero_Borrado){
|
|
||||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||||
if (fnDer->estado == EstadoFichero_Borrado) {
|
if (fnDer->estado == EstadoFichero_Borrado) {
|
||||||
afnNew->accion = AccionFileCmp_Nada;
|
afnNew->accion = AccionFileCmp_Nada;
|
||||||
@@ -390,8 +371,7 @@ void AccionFileNode_CheckPair(
|
|||||||
} else {
|
} else {
|
||||||
afnNew->accion = AccionFileCmp_Nada;
|
afnNew->accion = AccionFileCmp_Nada;
|
||||||
}
|
}
|
||||||
}else
|
} else if (fnIzq->ft < fnDer->ft) {
|
||||||
if(fnIzq->ft<fnDer->ft){
|
|
||||||
afnNew->accion = AccionFileCmp_DerechaAIzquierda;
|
afnNew->accion = AccionFileCmp_DerechaAIzquierda;
|
||||||
if (fnDer->estado == EstadoFichero_Borrado) {
|
if (fnDer->estado == EstadoFichero_Borrado) {
|
||||||
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
afnNew->accion = AccionFileCmp_BorrarIzquierda;
|
||||||
@@ -399,8 +379,7 @@ void AccionFileNode_CheckPair(
|
|||||||
afnNew->accion = AccionFileCmp_Nada;
|
afnNew->accion = AccionFileCmp_Nada;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else
|
} else if (fnIzq->ft > fnDer->ft) {
|
||||||
if(fnIzq->ft>fnDer->ft){
|
|
||||||
afnNew->accion = AccionFileCmp_IzquierdaADerecha;
|
afnNew->accion = AccionFileCmp_IzquierdaADerecha;
|
||||||
if (fnIzq->estado == EstadoFichero_Borrado) {
|
if (fnIzq->estado == EstadoFichero_Borrado) {
|
||||||
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
afnNew->accion = AccionFileCmp_BorrarDerecha;
|
||||||
@@ -422,29 +401,17 @@ void AccionFileNode_CheckPair(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AccionFileNode *AccionFileNode_BuildSync(FileNode *izquierda, FileNode *derecha) {
|
||||||
AccionFileNode *AccionFileNode_BuildSync(
|
|
||||||
FileNode *izquierda,FileNode *derecha)
|
|
||||||
{
|
|
||||||
AccionFileNode *afnRaiz = AccionFileNode_CrearNormal(izquierda, derecha);
|
AccionFileNode *afnRaiz = AccionFileNode_CrearNormal(izquierda, derecha);
|
||||||
AccionFileNode *afnCola = afnRaiz;
|
AccionFileNode *afnCola = afnRaiz;
|
||||||
|
|
||||||
AccionFileNode_CompareChilds(afnRaiz,&afnCola,
|
AccionFileNode_CompareChilds(afnRaiz, &afnCola, AccionFileNode_CheckPair);
|
||||||
AccionFileNode_CheckPair);
|
|
||||||
|
|
||||||
return afnRaiz;
|
return afnRaiz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AccionFileNode_Copy(FileNode *fnIzq, FileNode *fnDer,
|
||||||
|
AccionFileNode **afnCola) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AccionFileNode_Copy(
|
|
||||||
FileNode *fnIzq,FileNode *fnDer,AccionFileNode **afnCola)
|
|
||||||
{
|
|
||||||
AccionFileNode *afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
AccionFileNode *afnNew = AccionFileNode_CrearNormal(fnIzq, fnDer);
|
||||||
|
|
||||||
if (!fnIzq && !fnDer) {
|
if (!fnIzq && !fnDer) {
|
||||||
@@ -485,9 +452,8 @@ void AccionFileNode_Copy(
|
|||||||
(*afnCola) = afnNew;
|
(*afnCola) = afnNew;
|
||||||
}
|
}
|
||||||
if (fnIzq && fnDer) {
|
if (fnIzq && fnDer) {
|
||||||
if(fnIzq->flags&FileFlag_Directorio ||
|
if ((fnIzq->flags & FileFlag_Directorio)
|
||||||
fnDer->flags&FileFlag_Directorio)
|
|| (fnDer->flags & FileFlag_Directorio)) {
|
||||||
{
|
|
||||||
if (fnIzq->estado != EstadoFichero_Borrado) {
|
if (fnIzq->estado != EstadoFichero_Borrado) {
|
||||||
AccionFileNode_CompareChilds(afnNew, afnCola,
|
AccionFileNode_CompareChilds(afnNew, afnCola,
|
||||||
AccionFileNode_Copy);
|
AccionFileNode_Copy);
|
||||||
@@ -519,25 +485,15 @@ void AccionFileNode_Copy(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AccionFileNode *AccionFileNode_BuildCopy(FileNode *izquierda, FileNode *derecha) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AccionFileNode *AccionFileNode_BuildCopy(
|
|
||||||
FileNode *izquierda,FileNode *derecha)
|
|
||||||
{
|
|
||||||
AccionFileNode *afnRaiz = AccionFileNode_CrearNormal(izquierda, derecha);
|
AccionFileNode *afnRaiz = AccionFileNode_CrearNormal(izquierda, derecha);
|
||||||
AccionFileNode *afnCola = afnRaiz;
|
AccionFileNode *afnCola = afnRaiz;
|
||||||
|
|
||||||
AccionFileNode_CompareChilds(afnRaiz,&afnCola,
|
AccionFileNode_CompareChilds(afnRaiz, &afnCola, AccionFileNode_Copy);
|
||||||
AccionFileNode_Copy);
|
|
||||||
|
|
||||||
return afnRaiz;
|
return afnRaiz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AccionFileNode_Print(AccionFileNode *afn) {
|
void AccionFileNode_Print(AccionFileNode *afn) {
|
||||||
char showPath[MaxPath];
|
char showPath[MaxPath];
|
||||||
while (afn != NULL ) {
|
while (afn != NULL ) {
|
||||||
@@ -552,21 +508,29 @@ void AccionFileNode_Print(AccionFileNode *afn){
|
|||||||
//printf("%s == %s\n",pathIzq,pathDer);
|
//printf("%s == %s\n",pathIzq,pathDer);
|
||||||
break;
|
break;
|
||||||
case AccionFileCmp_IzquierdaADerecha:
|
case AccionFileCmp_IzquierdaADerecha:
|
||||||
printf(" => %s\n",showPath);break;
|
printf(" => %s\n", showPath);
|
||||||
|
break;
|
||||||
case AccionFileCmp_DerechaAIzquierda:
|
case AccionFileCmp_DerechaAIzquierda:
|
||||||
printf(" <= %s\n",showPath);break;
|
printf(" <= %s\n", showPath);
|
||||||
|
break;
|
||||||
case AccionFileCmp_BorrarIzquierda:
|
case AccionFileCmp_BorrarIzquierda:
|
||||||
printf(" *- %s\n",showPath);break;
|
printf(" *- %s\n", showPath);
|
||||||
|
break;
|
||||||
case AccionFileCmp_BorrarDerecha:
|
case AccionFileCmp_BorrarDerecha:
|
||||||
printf(" -* %s\n",showPath);break;
|
printf(" -* %s\n", showPath);
|
||||||
|
break;
|
||||||
case AccionFileCmp_FechaIzquierdaADerecha:
|
case AccionFileCmp_FechaIzquierdaADerecha:
|
||||||
printf(" -> %s\n",showPath);break;
|
printf(" -> %s\n", showPath);
|
||||||
|
break;
|
||||||
case AccionFileCmp_FechaDerechaAIzquierda:
|
case AccionFileCmp_FechaDerechaAIzquierda:
|
||||||
printf(" <- %s\n",showPath);break;
|
printf(" <- %s\n", showPath);
|
||||||
|
break;
|
||||||
case AccionFileCmp_CrearDirDerecha:
|
case AccionFileCmp_CrearDirDerecha:
|
||||||
printf(" -D %s\n",showPath);break;
|
printf(" -D %s\n", showPath);
|
||||||
|
break;
|
||||||
case AccionFileCmp_CrearDirIzquierda:
|
case AccionFileCmp_CrearDirIzquierda:
|
||||||
printf(" D- %s\n",showPath);break;
|
printf(" D- %s\n", showPath);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
afn = afn->sig;
|
afn = afn->sig;
|
||||||
@@ -574,10 +538,6 @@ void AccionFileNode_Print(AccionFileNode *afn){
|
|||||||
printf("End\n");
|
printf("End\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void AccionFileNodeAux_CopyDate(char *pathOrig, char *pathDest) {
|
void AccionFileNodeAux_CopyDate(char *pathOrig, char *pathDest) {
|
||||||
FileTime ft = FileTime_Get(pathOrig);
|
FileTime ft = FileTime_Get(pathOrig);
|
||||||
FileTime_Set(pathDest, ft);
|
FileTime_Set(pathDest, ft);
|
||||||
@@ -601,7 +561,8 @@ void AccionFileNodeAux_MakeDir(char *pathOrig,char *pathDest){
|
|||||||
File_CrearDir(pathDest);
|
File_CrearDir(pathDest);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccionFileNode_RunList(AccionFileNode *afn,char *pathIzquierda,char *pathDerecha){
|
void AccionFileNode_RunList(AccionFileNode *afn, char *pathIzquierda,
|
||||||
|
char *pathDerecha) {
|
||||||
char pathIzq[MaxPath], pathDer[MaxPath], showPath[MaxPath];
|
char pathIzq[MaxPath], pathDer[MaxPath], showPath[MaxPath];
|
||||||
while (afn != NULL ) {
|
while (afn != NULL ) {
|
||||||
if (afn->izquierda) {
|
if (afn->izquierda) {
|
||||||
@@ -620,7 +581,6 @@ void AccionFileNode_RunList(AccionFileNode *afn,char *pathIzquierda,char *pathDe
|
|||||||
FileNode_GetFullPath(afn->derecha, "", showPath);
|
FileNode_GetFullPath(afn->derecha, "", showPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (afn->accion) {
|
switch (afn->accion) {
|
||||||
case AccionFileCmp_Nada:
|
case AccionFileCmp_Nada:
|
||||||
//printf("%s == %s\n",pathIzq,pathDer);
|
//printf("%s == %s\n",pathIzq,pathDer);
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "filenode.h"
|
#include "filenode.h"
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
AccionFileCmp_Nada,
|
AccionFileCmp_Nada,
|
||||||
AccionFileCmp_IzquierdaADerecha,
|
AccionFileCmp_IzquierdaADerecha,
|
||||||
@@ -16,7 +15,6 @@ typedef enum {
|
|||||||
AccionFileCmp_CrearDirIzquierda
|
AccionFileCmp_CrearDirIzquierda
|
||||||
} AccionFileCmp;
|
} AccionFileCmp;
|
||||||
|
|
||||||
|
|
||||||
typedef struct Tag_AccionFileNode {
|
typedef struct Tag_AccionFileNode {
|
||||||
AccionFileCmp accion;
|
AccionFileCmp accion;
|
||||||
FileNode *izquierda;
|
FileNode *izquierda;
|
||||||
@@ -24,17 +22,18 @@ typedef struct Tag_AccionFileNode {
|
|||||||
struct Tag_AccionFileNode *sig;
|
struct Tag_AccionFileNode *sig;
|
||||||
} AccionFileNode;
|
} AccionFileNode;
|
||||||
|
|
||||||
|
|
||||||
AccionFileNode *AccionFileNode_Crear();
|
AccionFileNode *AccionFileNode_Crear();
|
||||||
void AccionFileNode_Destruir(AccionFileNode *afn);
|
void AccionFileNode_Destruir(AccionFileNode *afn);
|
||||||
AccionFileNode *AccionFileNode_CrearNormal(FileNode *fnIzq, FileNode *fnDer);
|
AccionFileNode *AccionFileNode_CrearNormal(FileNode *fnIzq, FileNode *fnDer);
|
||||||
|
|
||||||
AccionFileNode *AccionFileNode_BuildSync(FileNode *izquierda,FileNode *derecha);
|
AccionFileNode *AccionFileNode_BuildSync(FileNode *izquierda,
|
||||||
AccionFileNode *AccionFileNode_BuildCopy(FileNode *izquierda,FileNode *derecha);
|
FileNode *derecha);
|
||||||
|
AccionFileNode *AccionFileNode_BuildCopy(FileNode *izquierda,
|
||||||
|
FileNode *derecha);
|
||||||
|
|
||||||
void AccionFileNode_Print(AccionFileNode *afn);
|
void AccionFileNode_Print(AccionFileNode *afn);
|
||||||
|
|
||||||
void AccionFileNode_RunList(AccionFileNode *afn,
|
void AccionFileNode_RunList(AccionFileNode *afn, char *pathIzquierda,
|
||||||
char *pathIzquierda,char *pathDerecha);
|
char *pathDerecha);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
43
fileutil.c
43
fileutil.c
@@ -93,24 +93,15 @@ void FileTime_Set(char *filename,FileTime t){
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void FileTime_Print(FileTime t) {
|
void FileTime_Print(FileTime t) {
|
||||||
struct tm *tms;
|
struct tm *tms;
|
||||||
|
|
||||||
tms = localtime((time_t *) &t);
|
tms = localtime((time_t *) &t);
|
||||||
printf("%04d-%02d-%02d %02d:%02d:%02d",
|
printf("%04d-%02d-%02d %02d:%02d:%02d", tms->tm_year + 1900,
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void File_GetName(char *path, char *name) {
|
void File_GetName(char *path, char *name) {
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
@@ -129,14 +120,12 @@ void File_GetName(char *path,char *name){
|
|||||||
j = 0;
|
j = 0;
|
||||||
while (path[i]) {
|
while (path[i]) {
|
||||||
name[j] = path[i];
|
name[j] = path[i];
|
||||||
i++;j++;
|
i++;
|
||||||
|
j++;
|
||||||
}
|
}
|
||||||
name[j] = 0;
|
name[j] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
int File_ExistePath(char *path) {
|
int File_ExistePath(char *path) {
|
||||||
@@ -206,8 +195,6 @@ int File_EsFichero(char *fichero){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
long long File_TamanhoFichero(char *fichero) {
|
long long File_TamanhoFichero(char *fichero) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
long long tamanho;
|
long long tamanho;
|
||||||
@@ -222,7 +209,6 @@ long long File_TamanhoFichero(char *fichero){
|
|||||||
return (tamanho);
|
return (tamanho);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
int File_CrearDir(char *path) {
|
int File_CrearDir(char *path) {
|
||||||
return(_mkdir(path));
|
return(_mkdir(path));
|
||||||
@@ -233,9 +219,6 @@ int File_CrearDir(char *path){
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
|
|
||||||
void File_IterateDir(char *path,
|
void File_IterateDir(char *path,
|
||||||
@@ -274,8 +257,7 @@ void File_IterateDir(char *path,
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
void File_IterateDir(char *path,
|
void File_IterateDir(char *path,
|
||||||
int (*func)(char *path,char *name,void *data),void *data)
|
int (*func)(char *path, char *name, void *data), void *data) {
|
||||||
{
|
|
||||||
DIR *directorio;
|
DIR *directorio;
|
||||||
struct dirent *entidad_dir;
|
struct dirent *entidad_dir;
|
||||||
char f_path[MaxPath];
|
char f_path[MaxPath];
|
||||||
@@ -290,16 +272,12 @@ void File_IterateDir(char *path,
|
|||||||
do {
|
do {
|
||||||
entidad_dir = readdir(directorio);
|
entidad_dir = readdir(directorio);
|
||||||
if (entidad_dir != NULL ) {
|
if (entidad_dir != NULL ) {
|
||||||
if(strcmp(entidad_dir->d_name,".") &&
|
if (strcmp(entidad_dir->d_name, ".")
|
||||||
strcmp(entidad_dir->d_name,".."))
|
&& strcmp(entidad_dir->d_name, "..")) {
|
||||||
{
|
|
||||||
// A partir de aqui hay un fichero
|
// A partir de aqui hay un fichero
|
||||||
// (o directorio)
|
// (o directorio)
|
||||||
snprintf(f_path,MaxPath,
|
snprintf(f_path, MaxPath, "%s/%s", path, entidad_dir->d_name);
|
||||||
"%s/%s",path,entidad_dir->d_name);
|
fin = func(f_path, entidad_dir->d_name, data);
|
||||||
fin=func(f_path,
|
|
||||||
entidad_dir->d_name,
|
|
||||||
data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (entidad_dir != NULL && !fin);
|
} while (entidad_dir != NULL && !fin);
|
||||||
@@ -307,8 +285,6 @@ void File_IterateDir(char *path,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void File_Borrar(char *path) {
|
void File_Borrar(char *path) {
|
||||||
unlink(path);
|
unlink(path);
|
||||||
}
|
}
|
||||||
@@ -317,7 +293,6 @@ void File_BorrarDirectorio(char *path){
|
|||||||
rmdir(path);
|
rmdir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define MaxBuffer 16384
|
#define MaxBuffer 16384
|
||||||
int File_Copiar(const char *pathOrig, const char *pathDest) {
|
int File_Copiar(const char *pathOrig, const char *pathDest) {
|
||||||
FILE *fOrig, *fDest;
|
FILE *fOrig, *fDest;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#ifndef _FILEUTIL_
|
#ifndef _FILEUTIL_
|
||||||
#define _FILEUTIL_
|
#define _FILEUTIL_
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// FileTime
|
// FileTime
|
||||||
|
|
||||||
@@ -11,8 +10,6 @@ FileTime FileTime_Get(char *filename);
|
|||||||
void FileTime_Set(char *filename, FileTime t);
|
void FileTime_Set(char *filename, FileTime t);
|
||||||
void FileTime_Print(FileTime t);
|
void FileTime_Print(FileTime t);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////
|
///////////////////////////////////////////////
|
||||||
// File
|
// File
|
||||||
#define MaxPath 4096
|
#define MaxPath 4096
|
||||||
@@ -36,5 +33,4 @@ void File_IterateDir(char *path,
|
|||||||
void File_Borrar(char *path);
|
void File_Borrar(char *path);
|
||||||
void File_BorrarDirectorio(char *path);
|
void File_BorrarDirectorio(char *path);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
66
main.c
66
main.c
@@ -29,11 +29,9 @@ 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 *pathIzquierda, char *pathDerecha, int recheck, int dryrun);
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
unsigned long crc = 0;
|
unsigned long crc = 0;
|
||||||
@@ -56,18 +54,17 @@ int main(int argc,char *argv[]){
|
|||||||
}
|
}
|
||||||
ft = FileTime_Get(argv[i]);
|
ft = FileTime_Get(argv[i]);
|
||||||
printf("%s:\t[%08X]\t", argv[i], crc);
|
printf("%s:\t[%08X]\t", argv[i], crc);
|
||||||
FileTime_Print(ft);printf("\n");
|
FileTime_Print(ft);
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else
|
} else if (!strcmp(argv[1], "scan") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"scan") && argc==4){
|
|
||||||
// Scanear informacion de directorio y guardar arbol
|
// Scanear informacion de directorio y guardar arbol
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
printf("Building FileNode..\n");
|
printf("Building FileNode..\n");
|
||||||
fn = FileNode_Build(argv[2]);
|
fn = FileNode_Build(argv[2]);
|
||||||
FileNode_Save(fn, argv[3]);
|
FileNode_Save(fn, argv[3]);
|
||||||
}else
|
} else if (!strcmp(argv[1], "rescan") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"rescan") && argc==4){
|
|
||||||
// Scanear informacion de directorio y guardar arbol
|
// Scanear informacion de directorio y guardar arbol
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
printf("Loading FileNode..\n");
|
printf("Loading FileNode..\n");
|
||||||
@@ -77,14 +74,13 @@ int main(int argc,char *argv[]){
|
|||||||
fn = FileNode_Refresh(fn, argv[2]);
|
fn = FileNode_Refresh(fn, argv[2]);
|
||||||
FileNode_Save(fn, argv[3]);
|
FileNode_Save(fn, argv[3]);
|
||||||
}
|
}
|
||||||
}else
|
} else if (!strcmp(argv[1], "read") && argc == 3) {
|
||||||
if(!strcmp(argv[1],"read") && argc==3){
|
|
||||||
// Leer informacion de arbol
|
// Leer informacion de arbol
|
||||||
FileNode *fn;
|
FileNode *fn;
|
||||||
fn = FileNode_Load(argv[2]);
|
fn = FileNode_Load(argv[2]);
|
||||||
if(fn)FileNode_Print(fn);
|
if (fn)
|
||||||
}else
|
FileNode_Print(fn);
|
||||||
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];
|
||||||
@@ -94,58 +90,48 @@ int main(int argc,char *argv[]){
|
|||||||
if (fn) {
|
if (fn) {
|
||||||
FileNode_Print(fn);
|
FileNode_Print(fn);
|
||||||
}
|
}
|
||||||
}else
|
} else if (!strcmp(argv[1], "sync") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"sync") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
// Sincronizar dos directorios
|
||||||
char *pathIzquierda = argv[2];
|
char *pathIzquierda = argv[2];
|
||||||
char *pathDerecha = argv[3];
|
char *pathDerecha = argv[3];
|
||||||
sync(pathIzquierda, pathDerecha, 1, 0);
|
sync(pathIzquierda, pathDerecha, 1, 0);
|
||||||
}else
|
} else if (!strcmp(argv[1], "resync") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"resync") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
// Sincronizar dos directorios
|
||||||
char *pathIzquierda = argv[2];
|
char *pathIzquierda = argv[2];
|
||||||
char *pathDerecha = argv[3];
|
char *pathDerecha = argv[3];
|
||||||
sync(pathIzquierda, pathDerecha, 0, 0);
|
sync(pathIzquierda, pathDerecha, 0, 0);
|
||||||
}else
|
} else if (!strcmp(argv[1], "synctest") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"synctest") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
// Sincronizar dos directorios
|
||||||
char *pathIzquierda = argv[2];
|
char *pathIzquierda = argv[2];
|
||||||
char *pathDerecha = argv[3];
|
char *pathDerecha = argv[3];
|
||||||
sync(pathIzquierda, pathDerecha, 1, 1);
|
sync(pathIzquierda, pathDerecha, 1, 1);
|
||||||
}else
|
} else if (!strcmp(argv[1], "resynctest") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"resynctest") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
// Sincronizar dos directorios
|
||||||
char *pathIzquierda = argv[2];
|
char *pathIzquierda = argv[2];
|
||||||
char *pathDerecha = argv[3];
|
char *pathDerecha = argv[3];
|
||||||
sync(pathIzquierda, pathDerecha, 0, 1);
|
sync(pathIzquierda, pathDerecha, 0, 1);
|
||||||
|
|
||||||
|
} else if (!strcmp(argv[1], "copy") && argc == 4) {
|
||||||
}else
|
|
||||||
if(!strcmp(argv[1],"copy") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
// Sincronizar dos directorios
|
||||||
char *pathIzquierda = argv[2];
|
char *pathIzquierda = argv[2];
|
||||||
char *pathDerecha = argv[3];
|
char *pathDerecha = argv[3];
|
||||||
copy(pathIzquierda, pathDerecha, 1, 0);
|
copy(pathIzquierda, pathDerecha, 1, 0);
|
||||||
}else
|
} else if (!strcmp(argv[1], "recopy") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"recopy") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
// Sincronizar dos directorios
|
||||||
char *pathIzquierda = argv[2];
|
char *pathIzquierda = argv[2];
|
||||||
char *pathDerecha = argv[3];
|
char *pathDerecha = argv[3];
|
||||||
copy(pathIzquierda, pathDerecha, 0, 0);
|
copy(pathIzquierda, pathDerecha, 0, 0);
|
||||||
}else
|
} else if (!strcmp(argv[1], "copytest") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"copytest") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
// Sincronizar dos directorios
|
||||||
char *pathIzquierda = argv[2];
|
char *pathIzquierda = argv[2];
|
||||||
char *pathDerecha = argv[3];
|
char *pathDerecha = argv[3];
|
||||||
copy(pathIzquierda, pathDerecha, 1, 1);
|
copy(pathIzquierda, pathDerecha, 1, 1);
|
||||||
}else
|
} else if (!strcmp(argv[1], "recopytest") && argc == 4) {
|
||||||
if(!strcmp(argv[1],"recopytest") && argc==4){
|
|
||||||
// Sincronizar dos directorios
|
// Sincronizar dos directorios
|
||||||
char *pathIzquierda = argv[2];
|
char *pathIzquierda = argv[2];
|
||||||
char *pathDerecha = argv[3];
|
char *pathDerecha = argv[3];
|
||||||
copy(pathIzquierda, pathDerecha, 0, 1);
|
copy(pathIzquierda, pathDerecha, 0, 1);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
help(argv[0]);
|
help(argv[0]);
|
||||||
}
|
}
|
||||||
@@ -153,8 +139,6 @@ int main(int argc,char *argv[]){
|
|||||||
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 *fn;
|
||||||
@@ -195,10 +179,13 @@ int sync(char *pathIzquierda,char *pathDerecha,int recheck,int dryrun){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
fnIzquierda = checkDir(pathIzquierda, recheck);
|
fnIzquierda = checkDir(pathIzquierda, recheck);
|
||||||
if(!fnIzquierda){return 0;}
|
if (!fnIzquierda) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
fnDerecha = checkDir(pathDerecha, recheck);
|
fnDerecha = checkDir(pathDerecha, recheck);
|
||||||
if(!fnDerecha){return 0;}
|
if (!fnDerecha) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Construir acciones
|
// Construir acciones
|
||||||
printf("Building action list.. \n");
|
printf("Building action list.. \n");
|
||||||
@@ -231,10 +218,13 @@ int copy(char *pathIzquierda,char *pathDerecha,int recheck,int dryrun){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
fnIzquierda = checkDir(pathIzquierda, recheck);
|
fnIzquierda = checkDir(pathIzquierda, recheck);
|
||||||
if(!fnIzquierda){return 0;}
|
if (!fnIzquierda) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
fnDerecha = checkDir(pathDerecha, recheck);
|
fnDerecha = checkDir(pathDerecha, recheck);
|
||||||
if(!fnDerecha){return 0;}
|
if (!fnDerecha) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Construir acciones
|
// Construir acciones
|
||||||
printf("Building action list.. \n");
|
printf("Building action list.. \n");
|
||||||
|
|||||||
Reference in New Issue
Block a user