Code formating
This commit is contained in:
52
crc.c
52
crc.c
@@ -1,51 +1,49 @@
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned long CRCTable[256];
|
||||
int CRCTable_initialized=0;
|
||||
int CRCTable_initialized = 0;
|
||||
|
||||
#define CRC32_POLYNOMIAL 0xEDB88320L
|
||||
|
||||
void CRCTable_Init(){
|
||||
void CRCTable_Init() {
|
||||
int i;
|
||||
int j;
|
||||
unsigned long crc;
|
||||
|
||||
if(CRCTable_initialized){
|
||||
if (CRCTable_initialized) {
|
||||
return;
|
||||
}
|
||||
CRCTable_initialized=1;
|
||||
CRCTable_initialized = 1;
|
||||
|
||||
for (i=0;i<256;i++){
|
||||
crc=i;
|
||||
for (j=8;j>0;j--){
|
||||
if (crc&1)
|
||||
crc=(crc>>1)^CRC32_POLYNOMIAL;
|
||||
for (i = 0; i < 256; i++) {
|
||||
crc = i;
|
||||
for (j = 8; j > 0; j--) {
|
||||
if (crc & 1)
|
||||
crc = (crc >> 1) ^ CRC32_POLYNOMIAL;
|
||||
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_Buffer(unsigned char *buffer, int len, unsigned long crc) {
|
||||
unsigned char *p;
|
||||
unsigned long temp1;
|
||||
unsigned long temp2;
|
||||
|
||||
// Calcular CRC del buffer
|
||||
p=(unsigned char*)buffer;
|
||||
while(len--!=0) {
|
||||
temp1=(crc>>8)&0x00FFFFFFL;
|
||||
temp2=CRCTable[((int)crc^*p++)&0xff];
|
||||
crc=temp1^temp2;
|
||||
p = (unsigned char*) buffer;
|
||||
while (len-- != 0) {
|
||||
temp1 = (crc >> 8) & 0x00FFFFFFL;
|
||||
temp2 = CRCTable[((int) crc ^ *p++) & 0xff];
|
||||
crc = temp1 ^ temp2;
|
||||
}
|
||||
|
||||
return(crc);
|
||||
return (crc);
|
||||
}
|
||||
|
||||
|
||||
unsigned long CRC_File(FILE *file){
|
||||
unsigned long CRC_File(FILE *file) {
|
||||
unsigned long crc;
|
||||
int count;
|
||||
unsigned char buffer[512];
|
||||
@@ -55,15 +53,15 @@ unsigned long CRC_File(FILE *file){
|
||||
|
||||
CRCTable_Init();
|
||||
|
||||
crc=0xFFFFFFFFL;
|
||||
for(;;){
|
||||
crc = 0xFFFFFFFFL;
|
||||
for (;;) {
|
||||
// Llenar el buffer
|
||||
count=fread(buffer,1,512,file);
|
||||
if(count==0)
|
||||
count = fread(buffer, 1, 512, file);
|
||||
if (count == 0)
|
||||
break;
|
||||
|
||||
// Calcular CRC del buffer
|
||||
crc=CRC_Buffer(buffer,count,crc);
|
||||
crc = CRC_Buffer(buffer, count, crc);
|
||||
}
|
||||
return(crc^=0xFFFFFFFFL);
|
||||
return (crc ^= 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
2
crc.h
2
crc.h
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
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 long CRC_File(FILE *file);
|
||||
|
||||
#endif
|
||||
|
||||
567
filenode.c
567
filenode.c
@@ -7,312 +7,306 @@
|
||||
#include "fileutil.h"
|
||||
#include "filenode.h"
|
||||
|
||||
|
||||
|
||||
FileNode *_free_filenode=NULL;
|
||||
int _n_filenode=0;
|
||||
FileNode *_free_filenode = NULL;
|
||||
int _n_filenode = 0;
|
||||
#define FileNode_Tocho 1024
|
||||
FileNode *FileNode_New(){
|
||||
FileNode *FileNode_New() {
|
||||
FileNode *fn;
|
||||
|
||||
if(_free_filenode==NULL){
|
||||
if (_free_filenode == NULL ) {
|
||||
FileNode *nodos;
|
||||
int i;
|
||||
// Reservar un tocho
|
||||
nodos=malloc(sizeof(FileNode)*FileNode_Tocho);
|
||||
for(i=0;i<FileNode_Tocho-1;i++){
|
||||
nodos[i].sig=&nodos[i+1];
|
||||
nodos = malloc(sizeof(FileNode) * FileNode_Tocho);
|
||||
for (i = 0; i < FileNode_Tocho - 1; i++) {
|
||||
nodos[i].sig = &nodos[i + 1];
|
||||
}
|
||||
nodos[FileNode_Tocho-1].sig=NULL;
|
||||
_free_filenode=&nodos[0];
|
||||
nodos[FileNode_Tocho - 1].sig = NULL;
|
||||
_free_filenode = &nodos[0];
|
||||
}
|
||||
|
||||
// Obtener el primero libre
|
||||
fn=_free_filenode;
|
||||
_free_filenode=fn->sig;
|
||||
fn = _free_filenode;
|
||||
_free_filenode = fn->sig;
|
||||
_n_filenode++;
|
||||
|
||||
// Iniciar
|
||||
fn->name[0]=0;
|
||||
fn->flags=0;
|
||||
fn->estado=EstadoFichero_Nada;
|
||||
fn->size=0;
|
||||
fn->crc=0;
|
||||
fn->ft=0;
|
||||
fn->child=NULL;
|
||||
fn->n_childs=0;
|
||||
fn->sig=NULL;
|
||||
fn->padre=NULL;
|
||||
fn->name[0] = 0;
|
||||
fn->flags = 0;
|
||||
fn->estado = EstadoFichero_Nada;
|
||||
fn->size = 0;
|
||||
fn->crc = 0;
|
||||
fn->ft = 0;
|
||||
fn->child = NULL;
|
||||
fn->n_childs = 0;
|
||||
fn->sig = NULL;
|
||||
fn->padre = NULL;
|
||||
|
||||
return(fn);
|
||||
return (fn);
|
||||
}
|
||||
|
||||
void FileNode_Delete(FileNode *fn){
|
||||
fn->sig=_free_filenode;
|
||||
_free_filenode=fn;
|
||||
void FileNode_Delete(FileNode *fn) {
|
||||
fn->sig = _free_filenode;
|
||||
_free_filenode = fn;
|
||||
_n_filenode--;
|
||||
}
|
||||
|
||||
void FileNode_AddChild(FileNode *file,FileNode *file2){
|
||||
if(!file2 || !file)
|
||||
void FileNode_AddChild(FileNode *file, FileNode *file2) {
|
||||
if (!file2 || !file)
|
||||
return;
|
||||
file2->sig=file->child;
|
||||
file->child=file2;
|
||||
file2->sig = file->child;
|
||||
file->child = file2;
|
||||
file->n_childs++;
|
||||
file2->padre=file;
|
||||
file2->padre = file;
|
||||
}
|
||||
|
||||
|
||||
void FileNode_SetEstadoRec(FileNode *file,EstadoFichero estado){
|
||||
void FileNode_SetEstadoRec(FileNode *file, EstadoFichero estado) {
|
||||
FileNode *fn_child;
|
||||
file->estado=estado;
|
||||
fn_child=file->child;
|
||||
while(fn_child!=NULL){
|
||||
FileNode_SetEstadoRec(fn_child,estado);
|
||||
fn_child=fn_child->sig;
|
||||
file->estado = estado;
|
||||
fn_child = file->child;
|
||||
while (fn_child != NULL ) {
|
||||
FileNode_SetEstadoRec(fn_child, estado);
|
||||
fn_child = fn_child->sig;
|
||||
}
|
||||
}
|
||||
|
||||
void FileNode_GetPath_Rec(FileNode *fn,char **pathnode){
|
||||
if(fn->padre){
|
||||
pathnode[0]=fn->padre->name;
|
||||
FileNode_GetPath_Rec(fn->padre,pathnode+1);
|
||||
}else{
|
||||
pathnode[0]=NULL;
|
||||
void FileNode_GetPath_Rec(FileNode *fn, char **pathnode) {
|
||||
if (fn->padre) {
|
||||
pathnode[0] = fn->padre->name;
|
||||
FileNode_GetPath_Rec(fn->padre, pathnode + 1);
|
||||
} else {
|
||||
pathnode[0] = NULL;
|
||||
}
|
||||
}
|
||||
char temppath[MaxPath];
|
||||
char *FileNode_GetPath(FileNode *fn,char *path){
|
||||
char *FileNode_GetPath(FileNode *fn, char *path) {
|
||||
char *pathnodes[128];
|
||||
int levels,i;
|
||||
char *pathptr=temppath;
|
||||
if(path)pathptr=path;
|
||||
int levels, i;
|
||||
char *pathptr = temppath;
|
||||
if (path)
|
||||
pathptr = path;
|
||||
|
||||
FileNode_GetPath_Rec(fn,pathnodes);
|
||||
levels=0;while(pathnodes[levels]){levels++;}
|
||||
strcpy(pathptr,"");
|
||||
for(i=levels-1;i>=0;i--){
|
||||
strcat(pathptr,pathnodes[i]);
|
||||
strcat(pathptr,"/");
|
||||
FileNode_GetPath_Rec(fn, pathnodes);
|
||||
levels = 0;
|
||||
while (pathnodes[levels]) {
|
||||
levels++;
|
||||
}
|
||||
strcat(pathptr,fn->name);
|
||||
strcpy(pathptr, "");
|
||||
for (i = levels - 1; i >= 0; i--) {
|
||||
strcat(pathptr, pathnodes[i]);
|
||||
strcat(pathptr, "/");
|
||||
}
|
||||
strcat(pathptr, fn->name);
|
||||
return temppath;
|
||||
}
|
||||
char *FileNode_GetFullPath(FileNode *fn,char *basePath,char *path){
|
||||
char *FileNode_GetFullPath(FileNode *fn, char *basePath, char *path) {
|
||||
char *pathnodes[128];
|
||||
int levels,i;
|
||||
char *pathptr=temppath;
|
||||
if(path)pathptr=path;
|
||||
int levels, i;
|
||||
char *pathptr = temppath;
|
||||
if (path)
|
||||
pathptr = path;
|
||||
|
||||
FileNode_GetPath_Rec(fn,pathnodes);
|
||||
levels=0;while(pathnodes[levels]){levels++;}
|
||||
strcpy(pathptr,basePath);
|
||||
strcat(pathptr,"/");
|
||||
for(i=levels-2;i>=0;i--){
|
||||
strcat(pathptr,pathnodes[i]);
|
||||
strcat(pathptr,"/");
|
||||
FileNode_GetPath_Rec(fn, pathnodes);
|
||||
levels = 0;
|
||||
while (pathnodes[levels]) {
|
||||
levels++;
|
||||
}
|
||||
strcat(pathptr,fn->name);
|
||||
strcpy(pathptr, basePath);
|
||||
strcat(pathptr, "/");
|
||||
for (i = levels - 2; i >= 0; i--) {
|
||||
strcat(pathptr, pathnodes[i]);
|
||||
strcat(pathptr, "/");
|
||||
}
|
||||
strcat(pathptr, fn->name);
|
||||
return temppath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void FileNode_GetTamanho(FileNode *fn,char *file){
|
||||
fn->flags|=FileFlag_TieneTamanho;
|
||||
fn->size=File_TamanhoFichero(file);
|
||||
void FileNode_GetTamanho(FileNode *fn, char *file) {
|
||||
fn->flags |= FileFlag_TieneTamanho;
|
||||
fn->size = File_TamanhoFichero(file);
|
||||
}
|
||||
|
||||
void FileNode_GetFecha(FileNode *fn,char *file){
|
||||
fn->flags|=FileFlag_TieneFecha;
|
||||
fn->ft=FileTime_Get(file);
|
||||
void FileNode_GetFecha(FileNode *fn, char *file) {
|
||||
fn->flags |= FileFlag_TieneFecha;
|
||||
fn->ft = FileTime_Get(file);
|
||||
}
|
||||
|
||||
void FileNode_GetCRC(FileNode *fn,char *file){
|
||||
void FileNode_GetCRC(FileNode *fn, char *file) {
|
||||
FILE *f;
|
||||
f=fopen(file,"rb");
|
||||
if(!f){ return; }
|
||||
fn->flags|=FileFlag_TieneCRC;
|
||||
fn->crc=CRC_File(f);
|
||||
f = fopen(file, "rb");
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
fn->flags |= FileFlag_TieneCRC;
|
||||
fn->crc = CRC_File(f);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void FileNode_SaveNode(FileNode *fn,FILE *file){
|
||||
void FileNode_SaveNode(FileNode *fn, FILE *file) {
|
||||
short name_len;
|
||||
|
||||
// Escribir nombre
|
||||
name_len=strlen(fn->name);
|
||||
fwrite((void *)&name_len,sizeof(name_len),1,file);
|
||||
fputs(fn->name,file);
|
||||
name_len = strlen(fn->name);
|
||||
fwrite((void *) &name_len, sizeof(name_len), 1, file);
|
||||
fputs(fn->name, file);
|
||||
|
||||
// Escribir flags
|
||||
fwrite((void *)&fn->flags,sizeof(fn->flags),1,file);
|
||||
fwrite((void *) &fn->flags, sizeof(fn->flags), 1, file);
|
||||
|
||||
// Escribir estado
|
||||
fputc((char)fn->estado,file);
|
||||
fputc((char) fn->estado, file);
|
||||
|
||||
// Escribir tamanho
|
||||
if(fn->flags&FileFlag_TieneTamanho){
|
||||
fwrite((void *)&fn->size,sizeof(fn->size),1,file);
|
||||
if (fn->flags & FileFlag_TieneTamanho) {
|
||||
fwrite((void *) &fn->size, sizeof(fn->size), 1, file);
|
||||
}
|
||||
|
||||
// Escribir fecha
|
||||
if(fn->flags&FileFlag_TieneFecha){
|
||||
fwrite((void *)&fn->ft,sizeof(fn->ft),1,file);
|
||||
if (fn->flags & FileFlag_TieneFecha) {
|
||||
fwrite((void *) &fn->ft, sizeof(fn->ft), 1, file);
|
||||
}
|
||||
|
||||
// Escribir CRC
|
||||
if(fn->flags&FileFlag_TieneCRC){
|
||||
fwrite((void *)&fn->crc,sizeof(fn->crc),1,file);
|
||||
if (fn->flags & FileFlag_TieneCRC) {
|
||||
fwrite((void *) &fn->crc, sizeof(fn->crc), 1, file);
|
||||
}
|
||||
|
||||
// Escribir ficheros del directorio
|
||||
if(fn->flags&FileFlag_Directorio){
|
||||
if (fn->flags & FileFlag_Directorio) {
|
||||
FileNode *fnc;
|
||||
fwrite((void *)&fn->n_childs,sizeof(fn->n_childs),1,file);
|
||||
fnc=fn->child;
|
||||
while(fnc){
|
||||
FileNode_SaveNode(fnc,file);
|
||||
fnc=fnc->sig;
|
||||
fwrite((void *) &fn->n_childs, sizeof(fn->n_childs), 1, file);
|
||||
fnc = fn->child;
|
||||
while (fnc) {
|
||||
FileNode_SaveNode(fnc, file);
|
||||
fnc = fnc->sig;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FileNode_Save(FileNode *fn,char *fichero){
|
||||
void FileNode_Save(FileNode *fn, char *fichero) {
|
||||
FILE *file;
|
||||
char marca[5];
|
||||
int version;
|
||||
|
||||
if(!fn)
|
||||
if (!fn)
|
||||
return;
|
||||
file=fopen(fichero,"wb+");
|
||||
if(!file)
|
||||
file = fopen(fichero, "wb+");
|
||||
if (!file)
|
||||
return;
|
||||
|
||||
// Escribir marca y version
|
||||
strcpy(marca,"sYnC");
|
||||
fwrite((void *)marca,sizeof(char),4,file);
|
||||
version=FileNode_Version;
|
||||
fwrite((void *)&version,sizeof(int),1,file);
|
||||
strcpy(marca, "sYnC");
|
||||
fwrite((void *) marca, sizeof(char), 4, file);
|
||||
version = FileNode_Version;
|
||||
fwrite((void *) &version, sizeof(int), 1, file);
|
||||
|
||||
|
||||
FileNode_SaveNode(fn,file);
|
||||
FileNode_SaveNode(fn, file);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
|
||||
FileNode *FileNode_LoadNode(FILE *file){
|
||||
FileNode *FileNode_LoadNode(FILE *file) {
|
||||
short name_len;
|
||||
FileNode *fn;
|
||||
int i;
|
||||
|
||||
fn=FileNode_New();
|
||||
fn = FileNode_New();
|
||||
|
||||
// Leer el nombre
|
||||
fread((void *)&name_len,sizeof(name_len),1,file);
|
||||
fread((void *)fn->name,sizeof(char),name_len,file);
|
||||
fn->name[name_len]=0;
|
||||
fread((void *) &name_len, sizeof(name_len), 1, file);
|
||||
fread((void *) fn->name, sizeof(char), name_len, file);
|
||||
fn->name[name_len] = 0;
|
||||
|
||||
// Leer vanderas
|
||||
fread((void *)&fn->flags,sizeof(fn->flags),1,file);
|
||||
fread((void *) &fn->flags, sizeof(fn->flags), 1, file);
|
||||
|
||||
// Leer estado
|
||||
fn->estado=fgetc(file);
|
||||
fn->estado = fgetc(file);
|
||||
|
||||
// Leer tamanho
|
||||
if(fn->flags&FileFlag_TieneTamanho){
|
||||
fread((void *)&fn->size,sizeof(fn->size),1,file);
|
||||
if (fn->flags & FileFlag_TieneTamanho) {
|
||||
fread((void *) &fn->size, sizeof(fn->size), 1, file);
|
||||
}
|
||||
|
||||
// Leer fecha
|
||||
if(fn->flags&FileFlag_TieneFecha){
|
||||
fread((void *)&fn->ft,sizeof(fn->ft),1,file);
|
||||
if (fn->flags & FileFlag_TieneFecha) {
|
||||
fread((void *) &fn->ft, sizeof(fn->ft), 1, file);
|
||||
}
|
||||
|
||||
// Leer CRC
|
||||
if(fn->flags&FileFlag_TieneCRC){
|
||||
fread((void *)&fn->crc,sizeof(fn->crc),1,file);
|
||||
if (fn->flags & FileFlag_TieneCRC) {
|
||||
fread((void *) &fn->crc, sizeof(fn->crc), 1, file);
|
||||
}
|
||||
|
||||
// Leer ficheros del directorio
|
||||
if(fn->flags&FileFlag_Directorio){
|
||||
FileNode *fnca=NULL,*fnc;
|
||||
fread((void *)&fn->n_childs,sizeof(fn->n_childs),1,file);
|
||||
for(i=0;i<fn->n_childs;i++){
|
||||
fnc=FileNode_LoadNode(file);
|
||||
fnc->padre=fn;
|
||||
if(!fnca){
|
||||
fn->child=fnc;
|
||||
}else{
|
||||
fnca->sig=fnc;
|
||||
if (fn->flags & FileFlag_Directorio) {
|
||||
FileNode *fnca = NULL, *fnc;
|
||||
fread((void *) &fn->n_childs, sizeof(fn->n_childs), 1, file);
|
||||
for (i = 0; i < fn->n_childs; i++) {
|
||||
fnc = FileNode_LoadNode(file);
|
||||
fnc->padre = fn;
|
||||
if (!fnca) {
|
||||
fn->child = fnc;
|
||||
} else {
|
||||
fnca->sig = fnc;
|
||||
}
|
||||
fnca=fnc;
|
||||
fnca = fnc;
|
||||
}
|
||||
}
|
||||
|
||||
return(fn);
|
||||
return (fn);
|
||||
}
|
||||
|
||||
|
||||
FileNode *FileNode_Load(char *fichero){
|
||||
FileNode *FileNode_Load(char *fichero) {
|
||||
FILE *file;
|
||||
FileNode *fn;
|
||||
char marca[5];
|
||||
int version;
|
||||
|
||||
file=fopen(fichero,"rb");
|
||||
if(!file)
|
||||
return(NULL);
|
||||
file = fopen(fichero, "rb");
|
||||
if (!file)
|
||||
return (NULL );
|
||||
|
||||
// Leer marca y version
|
||||
fread((void *)marca,sizeof(char),4,file);
|
||||
marca[4]=0;
|
||||
if(strcmp(marca,"sYnC")){
|
||||
fread((void *) marca, sizeof(char), 4, file);
|
||||
marca[4] = 0;
|
||||
if (strcmp(marca, "sYnC")) {
|
||||
// Marca incorrecta
|
||||
fclose(file);
|
||||
return(NULL);
|
||||
return (NULL );
|
||||
}
|
||||
fread((void *)&version,sizeof(int),1,file);
|
||||
if(version!=FileNode_Version){
|
||||
fread((void *) &version, sizeof(int), 1, file);
|
||||
if (version != FileNode_Version) {
|
||||
// Version incorrecta
|
||||
fclose(file);
|
||||
return(NULL);
|
||||
return (NULL );
|
||||
}
|
||||
|
||||
|
||||
fn=FileNode_LoadNode(file);
|
||||
fn = FileNode_LoadNode(file);
|
||||
fclose(file);
|
||||
|
||||
return(fn);
|
||||
return (fn);
|
||||
}
|
||||
|
||||
|
||||
void FileNode_PrintNode(FileNode *fn){
|
||||
printf(FileNode_GetPath(fn,NULL));
|
||||
if(fn->flags&FileFlag_Normal){
|
||||
void FileNode_PrintNode(FileNode *fn) {
|
||||
printf(FileNode_GetPath(fn, NULL ));
|
||||
if (fn->flags & FileFlag_Normal) {
|
||||
printf(" File");
|
||||
}else{
|
||||
} else {
|
||||
printf(" Dir");
|
||||
}
|
||||
printf(" %d",fn->estado);
|
||||
if(fn->estado==EstadoFichero_Nuevo){
|
||||
printf(" %d", fn->estado);
|
||||
if (fn->estado == EstadoFichero_Nuevo) {
|
||||
printf(" Nuevo");
|
||||
}
|
||||
if(fn->estado==EstadoFichero_Modificado){
|
||||
if (fn->estado == EstadoFichero_Modificado) {
|
||||
printf(" Modificado");
|
||||
}
|
||||
if(fn->estado==EstadoFichero_Borrado){
|
||||
if (fn->estado == EstadoFichero_Borrado) {
|
||||
printf(" Borrado!!!");
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
/*
|
||||
/*
|
||||
// Tamanho
|
||||
if(fn->flags&FileFlag_TieneTamanho){
|
||||
printf("\\-Tamanho: %lld\n",fn->size);
|
||||
@@ -327,227 +321,190 @@ void FileNode_PrintNode(FileNode *fn){
|
||||
if(fn->flags&FileFlag_TieneCRC){
|
||||
printf("\\-CRC : [%08X]\n",fn->crc);
|
||||
}
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
void FileNode_Print(FileNode *fn) {
|
||||
FileNode *fnAux = fn;
|
||||
int end = 0;
|
||||
|
||||
void FileNode_Print(FileNode *fn){
|
||||
FileNode *fnAux=fn;
|
||||
int end=0;
|
||||
while (fnAux != NULL && !end) {
|
||||
|
||||
while(fnAux!=NULL && !end){
|
||||
|
||||
if(fnAux->padre!=NULL){
|
||||
if (fnAux->padre != NULL ) {
|
||||
FileNode_PrintNode(fnAux);
|
||||
}
|
||||
|
||||
if(fnAux->child){
|
||||
fnAux=fnAux->child;
|
||||
}else{
|
||||
while(fnAux->sig==NULL){
|
||||
fnAux=fnAux->padre;
|
||||
if(fnAux==fn || fnAux==NULL){
|
||||
if (fnAux->child) {
|
||||
fnAux = fnAux->child;
|
||||
} else {
|
||||
while (fnAux->sig == NULL ) {
|
||||
fnAux = fnAux->padre;
|
||||
if (fnAux == fn || fnAux == NULL ) {
|
||||
printf("End\n");
|
||||
end=1;
|
||||
end = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!end){
|
||||
fnAux=fnAux->sig;
|
||||
if (!end) {
|
||||
fnAux = fnAux->sig;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if(!File_ExistePath(path))
|
||||
return(NULL);
|
||||
if (!File_ExistePath(path))
|
||||
return (NULL );
|
||||
|
||||
// Crear el nodo
|
||||
file=FileNode_New();
|
||||
File_GetName(path,file->name);
|
||||
file = FileNode_New();
|
||||
File_GetName(path, file->name);
|
||||
|
||||
// Determinar si es un fichero o directorio
|
||||
if(File_EsDirectorio(path)){
|
||||
if (File_EsDirectorio(path)) {
|
||||
// Obtener datos para los directorios
|
||||
file->flags|=FileFlag_Directorio;
|
||||
FileNode_GetFecha(file,path);
|
||||
File_IterateDir(path,FileNode_Build_Iterate,file);
|
||||
}else{
|
||||
file->flags |= FileFlag_Directorio;
|
||||
FileNode_GetFecha(file, path);
|
||||
File_IterateDir(path, FileNode_Build_Iterate, file);
|
||||
} else {
|
||||
// Obtener datos para los ficheros
|
||||
file->flags|=FileFlag_Normal;
|
||||
FileNode_GetTamanho(file,path);
|
||||
FileNode_GetFecha(file,path);
|
||||
file->flags |= FileFlag_Normal;
|
||||
FileNode_GetTamanho(file, path);
|
||||
FileNode_GetFecha(file, path);
|
||||
}
|
||||
|
||||
return(file);
|
||||
return (file);
|
||||
}
|
||||
|
||||
int FileNode_Build_Iterate(char *path, char *name, void *d) {
|
||||
FileNode *file, *fn_padre = d;
|
||||
;
|
||||
|
||||
int FileNode_Build_Iterate(char *path,char *name,void *d){
|
||||
FileNode *file,*fn_padre=d;;
|
||||
|
||||
if(!strcmp(name,FileNode_Filename)){
|
||||
return(0);
|
||||
if (!strcmp(name, FileNode_Filename)) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
file=FileNode_Build(path);
|
||||
FileNode_AddChild(fn_padre,file);
|
||||
file = FileNode_Build(path);
|
||||
FileNode_AddChild(fn_padre, file);
|
||||
|
||||
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){
|
||||
if(!File_ExistePath(path)){
|
||||
FileNode *FileNode_Refresh(FileNode *fn, char *path) {
|
||||
if (!File_ExistePath(path)) {
|
||||
// El fichero/directorio ha sido borrado
|
||||
if(!fn){
|
||||
fn=FileNode_New();
|
||||
File_GetName(path,fn->name);
|
||||
if (!fn) {
|
||||
fn = FileNode_New();
|
||||
File_GetName(path, fn->name);
|
||||
}
|
||||
FileNode_SetEstadoRec(fn,EstadoFichero_Borrado);
|
||||
return(fn);
|
||||
FileNode_SetEstadoRec(fn, EstadoFichero_Borrado);
|
||||
return (fn);
|
||||
}
|
||||
if(!fn){
|
||||
if (!fn) {
|
||||
// El fichero ha sido creado
|
||||
fn=FileNode_Build(path);
|
||||
FileNode_SetEstadoRec(fn,EstadoFichero_Nuevo);
|
||||
}else{
|
||||
fn = FileNode_Build(path);
|
||||
FileNode_SetEstadoRec(fn, EstadoFichero_Nuevo);
|
||||
} else {
|
||||
// Comprobar si ha sido modificado
|
||||
FileTime ft;
|
||||
long long size;
|
||||
int crc;
|
||||
|
||||
// Marcar normal
|
||||
fn->estado=EstadoFichero_Nada;
|
||||
fn->flags&=~FileFlag_MarcaRevision;
|
||||
fn->estado = EstadoFichero_Nada;
|
||||
fn->flags &= ~FileFlag_MarcaRevision;
|
||||
|
||||
// Determinar si es un fichero o directorio
|
||||
if(File_EsDirectorio(path)){
|
||||
if (File_EsDirectorio(path)) {
|
||||
FileNode *fn_child;
|
||||
|
||||
// Comparar datos de los directorios
|
||||
if(!(fn->flags&FileFlag_Directorio)){
|
||||
fn->estado=EstadoFichero_Modificado;
|
||||
fn->flags|=FileFlag_Directorio;
|
||||
fn->flags&=~FileFlag_Normal;
|
||||
if (!(fn->flags & FileFlag_Directorio)) {
|
||||
fn->estado = EstadoFichero_Modificado;
|
||||
fn->flags |= FileFlag_Directorio;
|
||||
fn->flags &= ~FileFlag_Normal;
|
||||
}
|
||||
ft=FileTime_Get(path);
|
||||
if(ft!=fn->ft){
|
||||
fn->estado=EstadoFichero_Modificado;
|
||||
fn->ft=ft;
|
||||
ft = FileTime_Get(path);
|
||||
if (ft != fn->ft) {
|
||||
fn->estado = EstadoFichero_Modificado;
|
||||
fn->ft = ft;
|
||||
}
|
||||
|
||||
// Marcar hijos para determinar cual es actualizado
|
||||
fn_child=fn->child;while(fn_child){
|
||||
fn_child->flags|=FileFlag_MarcaRevision;
|
||||
fn_child=fn_child->sig;
|
||||
fn_child = fn->child;
|
||||
while (fn_child) {
|
||||
fn_child->flags |= FileFlag_MarcaRevision;
|
||||
fn_child = fn_child->sig;
|
||||
}
|
||||
|
||||
// Escanear subdirectorios
|
||||
File_IterateDir(path,FileNode_Refresh_Iterate,fn);
|
||||
File_IterateDir(path, FileNode_Refresh_Iterate, fn);
|
||||
|
||||
// Buscar que sigan marcados (borrados)
|
||||
fn_child=fn->child;while(fn_child){
|
||||
if(fn_child->flags&FileFlag_MarcaRevision){
|
||||
fn_child->flags&=~FileFlag_MarcaRevision;
|
||||
FileNode_SetEstadoRec(fn_child,EstadoFichero_Borrado);
|
||||
fn_child = fn->child;
|
||||
while (fn_child) {
|
||||
if (fn_child->flags & FileFlag_MarcaRevision) {
|
||||
fn_child->flags &= ~FileFlag_MarcaRevision;
|
||||
FileNode_SetEstadoRec(fn_child, EstadoFichero_Borrado);
|
||||
}
|
||||
fn_child=fn_child->sig;
|
||||
fn_child = fn_child->sig;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
// Comprar datos de los ficheros
|
||||
if(!(fn->flags&FileFlag_Normal)){
|
||||
fn->estado=EstadoFichero_Modificado;
|
||||
fn->flags|=FileFlag_Normal;
|
||||
fn->flags&=~FileFlag_Directorio;
|
||||
if (!(fn->flags & FileFlag_Normal)) {
|
||||
fn->estado = EstadoFichero_Modificado;
|
||||
fn->flags |= FileFlag_Normal;
|
||||
fn->flags &= ~FileFlag_Directorio;
|
||||
}
|
||||
size=File_TamanhoFichero(path);
|
||||
if(size!=fn->size){
|
||||
fn->estado=EstadoFichero_Modificado;
|
||||
fn->size=size;
|
||||
size = File_TamanhoFichero(path);
|
||||
if (size != fn->size) {
|
||||
fn->estado = EstadoFichero_Modificado;
|
||||
fn->size = size;
|
||||
}
|
||||
ft=FileTime_Get(path);
|
||||
if(ft!=fn->ft){
|
||||
fn->estado=EstadoFichero_Modificado;
|
||||
fn->ft=ft;
|
||||
ft = FileTime_Get(path);
|
||||
if (ft != fn->ft) {
|
||||
fn->estado = EstadoFichero_Modificado;
|
||||
fn->ft = ft;
|
||||
}
|
||||
if(fn->estado==EstadoFichero_Modificado){
|
||||
fn->flags&=~FileFlag_TieneCRC;
|
||||
if (fn->estado == EstadoFichero_Modificado) {
|
||||
fn->flags &= ~FileFlag_TieneCRC;
|
||||
}
|
||||
}
|
||||
}
|
||||
return(fn);
|
||||
return (fn);
|
||||
}
|
||||
|
||||
int FileNode_Refresh_Iterate(char *path,char *name,void *d){
|
||||
FileNode *fn=d;
|
||||
int FileNode_Refresh_Iterate(char *path, char *name, void *d) {
|
||||
FileNode *fn = d;
|
||||
FileNode *fn_child;
|
||||
|
||||
if(!strcmp(name,FileNode_Filename)){
|
||||
return(0);
|
||||
if (!strcmp(name, FileNode_Filename)) {
|
||||
return (0);
|
||||
}
|
||||
|
||||
// Buscar el fichero entre los del arbol
|
||||
fn_child=fn->child;
|
||||
while(fn_child){
|
||||
if(!strcmp(fn_child->name,name)){
|
||||
fn_child = fn->child;
|
||||
while (fn_child) {
|
||||
if (!strcmp(fn_child->name, name)) {
|
||||
break;
|
||||
}
|
||||
fn_child=fn_child->sig;
|
||||
fn_child = fn_child->sig;
|
||||
}
|
||||
if(fn_child){
|
||||
if (fn_child) {
|
||||
// Existe, refrescar
|
||||
FileNode_Refresh(fn_child,path);
|
||||
}else{
|
||||
FileNode_Refresh(fn_child, path);
|
||||
} else {
|
||||
// Nuevo, construir
|
||||
fn_child=FileNode_Refresh(NULL,path);
|
||||
FileNode_AddChild(fn,fn_child);
|
||||
fn_child = FileNode_Refresh(NULL, path);
|
||||
FileNode_AddChild(fn, fn_child);
|
||||
}
|
||||
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
18
filenode.h
18
filenode.h
@@ -20,7 +20,7 @@ typedef enum {
|
||||
EstadoFichero_Borrado
|
||||
} EstadoFichero;
|
||||
|
||||
typedef struct FileNode_Tag{
|
||||
typedef struct FileNode_Tag {
|
||||
char name[MaxFilename];
|
||||
|
||||
int flags;
|
||||
@@ -42,24 +42,22 @@ typedef struct FileNode_Tag{
|
||||
|
||||
FileNode *FileNode_New();
|
||||
void FileNode_Delete(FileNode *fn);
|
||||
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 *fn, char *basePath, char *path);
|
||||
|
||||
void FileNode_GetTamanho(FileNode *fn,char *file);
|
||||
void FileNode_GetFecha(FileNode *fn,char *file);
|
||||
void FileNode_GetCRC(FileNode *fn,char *file);
|
||||
void FileNode_GetTamanho(FileNode *fn, char *file);
|
||||
void FileNode_GetFecha(FileNode *fn, char *file);
|
||||
void FileNode_GetCRC(FileNode *fn, char *file);
|
||||
|
||||
void FileNode_Save(FileNode *fn,char *fichero);
|
||||
void FileNode_Save(FileNode *fn, char *fichero);
|
||||
FileNode *FileNode_Load(char *fichero);
|
||||
|
||||
void FileNode_PrintNode(FileNode *fn);
|
||||
void FileNode_Print(FileNode *fn);
|
||||
|
||||
|
||||
FileNode *FileNode_Build(char *path);
|
||||
|
||||
FileNode *FileNode_Refresh(FileNode *file,char *path);
|
||||
|
||||
FileNode *FileNode_Refresh(FileNode *file, char *path);
|
||||
|
||||
#endif
|
||||
|
||||
738
filenodecmp.c
738
filenodecmp.c
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,6 @@
|
||||
|
||||
#include "filenode.h"
|
||||
|
||||
|
||||
typedef enum {
|
||||
AccionFileCmp_Nada,
|
||||
AccionFileCmp_IzquierdaADerecha,
|
||||
@@ -16,7 +15,6 @@ typedef enum {
|
||||
AccionFileCmp_CrearDirIzquierda
|
||||
} AccionFileCmp;
|
||||
|
||||
|
||||
typedef struct Tag_AccionFileNode {
|
||||
AccionFileCmp accion;
|
||||
FileNode *izquierda;
|
||||
@@ -24,17 +22,18 @@ typedef struct Tag_AccionFileNode {
|
||||
struct Tag_AccionFileNode *sig;
|
||||
} AccionFileNode;
|
||||
|
||||
|
||||
AccionFileNode *AccionFileNode_Crear();
|
||||
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_BuildCopy(FileNode *izquierda,FileNode *derecha);
|
||||
AccionFileNode *AccionFileNode_BuildSync(FileNode *izquierda,
|
||||
FileNode *derecha);
|
||||
AccionFileNode *AccionFileNode_BuildCopy(FileNode *izquierda,
|
||||
FileNode *derecha);
|
||||
|
||||
void AccionFileNode_Print(AccionFileNode *afn);
|
||||
|
||||
void AccionFileNode_RunList(AccionFileNode *afn,
|
||||
char *pathIzquierda,char *pathDerecha);
|
||||
void AccionFileNode_RunList(AccionFileNode *afn, char *pathIzquierda,
|
||||
char *pathDerecha);
|
||||
|
||||
#endif
|
||||
|
||||
221
fileutil.c
221
fileutil.c
@@ -7,19 +7,19 @@
|
||||
#include <utime.h>
|
||||
#include <time.h>
|
||||
#ifdef WIN32
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#include <signal.h>
|
||||
#include <windows.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#include <signal.h>
|
||||
#include <windows.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "fileutil.h"
|
||||
|
||||
#ifdef WIN32
|
||||
long long FileTime_to_POSIX(FILETIME ft){
|
||||
long long FileTime_to_POSIX(FILETIME ft) {
|
||||
LARGE_INTEGER date, adjust;
|
||||
|
||||
// takes the last modified date
|
||||
@@ -36,7 +36,7 @@ long long FileTime_to_POSIX(FILETIME ft){
|
||||
return date.QuadPart / 10000000ll;
|
||||
}
|
||||
|
||||
FILETIME POSIX_to_FileTime(FileTime ft){
|
||||
FILETIME POSIX_to_FileTime(FileTime ft) {
|
||||
LARGE_INTEGER date, adjust;
|
||||
FILETIME filetime;
|
||||
|
||||
@@ -55,7 +55,7 @@ FILETIME POSIX_to_FileTime(FileTime ft){
|
||||
return filetime;
|
||||
}
|
||||
|
||||
FileTime FileTime_Get(char *filename){
|
||||
FileTime FileTime_Get(char *filename) {
|
||||
HANDLE hFile;
|
||||
FILETIME ftCreate, ftAccess, ftWrite;
|
||||
hFile = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
|
||||
@@ -65,7 +65,7 @@ FileTime FileTime_Get(char *filename){
|
||||
return(FileTime_to_POSIX(ftWrite));
|
||||
}
|
||||
|
||||
void FileTime_Set(char *filename,FileTime t){
|
||||
void FileTime_Set(char *filename,FileTime t) {
|
||||
HANDLE hFile;
|
||||
FILETIME ftWrite;
|
||||
hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE,
|
||||
@@ -77,165 +77,148 @@ void FileTime_Set(char *filename,FileTime t){
|
||||
|
||||
#else
|
||||
|
||||
FileTime FileTime_Get(char *filename){
|
||||
FileTime FileTime_Get(char *filename) {
|
||||
struct stat fs;
|
||||
lstat(filename,&fs);
|
||||
return(fs.st_mtime);
|
||||
lstat(filename, &fs);
|
||||
return (fs.st_mtime);
|
||||
}
|
||||
|
||||
void FileTime_Set(char *filename,FileTime t){
|
||||
void FileTime_Set(char *filename, FileTime t) {
|
||||
struct utimbuf utb;
|
||||
|
||||
utb.actime=t;
|
||||
utb.modtime=t;
|
||||
utime(filename,&utb);
|
||||
utb.actime = t;
|
||||
utb.modtime = t;
|
||||
utime(filename, &utb);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void FileTime_Print(FileTime t){
|
||||
void FileTime_Print(FileTime t) {
|
||||
struct tm *tms;
|
||||
|
||||
tms=localtime((time_t *)&t);
|
||||
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 = localtime((time_t *) &t);
|
||||
printf("%04d-%02d-%02d %02d:%02d:%02d", tms->tm_year + 1900,
|
||||
tms->tm_mon + 1, tms->tm_mday, tms->tm_hour, tms->tm_min,
|
||||
tms->tm_sec);
|
||||
}
|
||||
|
||||
void File_GetName(char *path, char *name) {
|
||||
int i, j;
|
||||
|
||||
|
||||
|
||||
|
||||
void File_GetName(char *path,char *name){
|
||||
int i,j;
|
||||
|
||||
i=strlen(path)-1;
|
||||
while(i>=0 ){
|
||||
if(path[i]=='/' || path[i]=='\\'){
|
||||
i = strlen(path) - 1;
|
||||
while (i >= 0) {
|
||||
if (path[i] == '/' || path[i] == '\\') {
|
||||
i++;
|
||||
break;
|
||||
}else{
|
||||
} else {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
if(i<0)
|
||||
if (i < 0)
|
||||
i++;
|
||||
|
||||
j=0;
|
||||
while(path[i]){
|
||||
name[j]=path[i];
|
||||
i++;j++;
|
||||
j = 0;
|
||||
while (path[i]) {
|
||||
name[j] = path[i];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
name[j]=0;
|
||||
name[j] = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
int File_ExistePath(char *path){
|
||||
int File_ExistePath(char *path) {
|
||||
unsigned rc;
|
||||
rc=GetFileAttributes(path);
|
||||
|
||||
if(rc==INVALID_FILE_ATTRIBUTES){
|
||||
if(rc==INVALID_FILE_ATTRIBUTES) {
|
||||
return(0);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
int File_EsDirectorio(char *dir){
|
||||
int File_EsDirectorio(char *dir) {
|
||||
unsigned rc;
|
||||
rc=GetFileAttributes(dir);
|
||||
|
||||
if(rc==INVALID_FILE_ATTRIBUTES){
|
||||
if(rc==INVALID_FILE_ATTRIBUTES) {
|
||||
return(0);
|
||||
}
|
||||
if(rc&FILE_ATTRIBUTE_DIRECTORY){
|
||||
if(rc&FILE_ATTRIBUTE_DIRECTORY) {
|
||||
return(1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
int File_EsFichero(char *fichero){
|
||||
int File_EsFichero(char *fichero) {
|
||||
unsigned rc;
|
||||
rc=GetFileAttributes(fichero);
|
||||
|
||||
if(rc==INVALID_FILE_ATTRIBUTES){
|
||||
if(rc==INVALID_FILE_ATTRIBUTES) {
|
||||
return(0);
|
||||
}
|
||||
if(rc&FILE_ATTRIBUTE_DIRECTORY){
|
||||
if(rc&FILE_ATTRIBUTE_DIRECTORY) {
|
||||
return(0);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
||||
#else
|
||||
int File_ExistePath(char *path){
|
||||
int File_ExistePath(char *path) {
|
||||
struct stat info;
|
||||
|
||||
if(lstat(path,&info)==-1){
|
||||
return(0);
|
||||
if (lstat(path, &info) == -1) {
|
||||
return (0);
|
||||
}
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
int File_EsDirectorio(char *dir){
|
||||
int File_EsDirectorio(char *dir) {
|
||||
struct stat info;
|
||||
|
||||
if(lstat(dir,&info)==-1){
|
||||
return(0);
|
||||
if (lstat(dir, &info) == -1) {
|
||||
return (0);
|
||||
}
|
||||
if(S_ISDIR(info.st_mode)){
|
||||
return(1);
|
||||
if (S_ISDIR(info.st_mode)) {
|
||||
return (1);
|
||||
}
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
int File_EsFichero(char *fichero){
|
||||
int File_EsFichero(char *fichero) {
|
||||
struct stat info;
|
||||
|
||||
if(lstat(fichero,&info)==-1){
|
||||
return(0);
|
||||
if (lstat(fichero, &info) == -1) {
|
||||
return (0);
|
||||
}
|
||||
if(S_ISDIR(info.st_mode)){
|
||||
return(0);
|
||||
if (S_ISDIR(info.st_mode)) {
|
||||
return (0);
|
||||
}
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
long long File_TamanhoFichero(char *fichero){
|
||||
long long File_TamanhoFichero(char *fichero) {
|
||||
FILE *f;
|
||||
long long tamanho;
|
||||
|
||||
f=fopen(fichero,"rb");
|
||||
if(!f)
|
||||
return(-1);
|
||||
f = fopen(fichero, "rb");
|
||||
if (!f)
|
||||
return (-1);
|
||||
|
||||
fseek(f,0,SEEK_END);
|
||||
tamanho=ftell(f);
|
||||
fseek(f, 0, SEEK_END);
|
||||
tamanho = ftell(f);
|
||||
fclose(f);
|
||||
return(tamanho);
|
||||
return (tamanho);
|
||||
}
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
int File_CrearDir(char *path){
|
||||
int File_CrearDir(char *path) {
|
||||
return(_mkdir(path));
|
||||
}
|
||||
#else
|
||||
int File_CrearDir(char *path){
|
||||
return(mkdir(path,0777));
|
||||
int File_CrearDir(char *path) {
|
||||
return (mkdir(path, 0777));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
void File_IterateDir(char *path,
|
||||
@@ -256,7 +239,7 @@ void File_IterateDir(char *path,
|
||||
return;
|
||||
|
||||
// Recorrer el directorio
|
||||
do{
|
||||
do {
|
||||
if(strcmp(fileinfo.name,".") &&
|
||||
strcmp(fileinfo.name,".."))
|
||||
{
|
||||
@@ -274,80 +257,72 @@ void File_IterateDir(char *path,
|
||||
#else
|
||||
|
||||
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;
|
||||
struct dirent *entidad_dir;
|
||||
char f_path[MaxPath];
|
||||
int fin=0;
|
||||
int fin = 0;
|
||||
char *ptr;
|
||||
|
||||
directorio=opendir(path);
|
||||
if(directorio==NULL)
|
||||
directorio = opendir(path);
|
||||
if (directorio == NULL )
|
||||
return;
|
||||
|
||||
// Recorrer el directorio
|
||||
do{
|
||||
entidad_dir=readdir(directorio);
|
||||
if(entidad_dir!=NULL){
|
||||
if(strcmp(entidad_dir->d_name,".") &&
|
||||
strcmp(entidad_dir->d_name,".."))
|
||||
{
|
||||
do {
|
||||
entidad_dir = readdir(directorio);
|
||||
if (entidad_dir != NULL ) {
|
||||
if (strcmp(entidad_dir->d_name, ".")
|
||||
&& strcmp(entidad_dir->d_name, "..")) {
|
||||
// A partir de aqui hay un fichero
|
||||
// (o directorio)
|
||||
snprintf(f_path,MaxPath,
|
||||
"%s/%s",path,entidad_dir->d_name);
|
||||
fin=func(f_path,
|
||||
entidad_dir->d_name,
|
||||
data);
|
||||
snprintf(f_path, MaxPath, "%s/%s", path, entidad_dir->d_name);
|
||||
fin = func(f_path, entidad_dir->d_name, data);
|
||||
}
|
||||
}
|
||||
}while(entidad_dir!=NULL && !fin);
|
||||
} while (entidad_dir != NULL && !fin);
|
||||
closedir(directorio);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void File_Borrar(char *path){
|
||||
void File_Borrar(char *path) {
|
||||
unlink(path);
|
||||
}
|
||||
|
||||
void File_BorrarDirectorio(char *path){
|
||||
void File_BorrarDirectorio(char *path) {
|
||||
rmdir(path);
|
||||
}
|
||||
|
||||
|
||||
#define MaxBuffer 16384
|
||||
int File_Copiar( const char *pathOrig,const char *pathDest){
|
||||
FILE *fOrig,*fDest;
|
||||
int File_Copiar(const char *pathOrig, const char *pathDest) {
|
||||
FILE *fOrig, *fDest;
|
||||
char buffer[MaxBuffer];
|
||||
int readLen=0;
|
||||
int writeLen=0;
|
||||
int ok=0;
|
||||
int readLen = 0;
|
||||
int writeLen = 0;
|
||||
int ok = 0;
|
||||
|
||||
if((fOrig=fopen(pathOrig,"rb"))==NULL){
|
||||
if ((fOrig = fopen(pathOrig, "rb")) == NULL ) {
|
||||
return 0;
|
||||
}
|
||||
if((fDest=fopen(pathDest,"wb"))==NULL){
|
||||
if ((fDest = fopen(pathDest, "wb")) == NULL ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
do{
|
||||
readLen=fread(&buffer,1,MaxBuffer,fOrig);
|
||||
if(readLen>0){
|
||||
writeLen=fwrite(&buffer,1,readLen,fDest);
|
||||
if(writeLen!=readLen){
|
||||
do {
|
||||
readLen = fread(&buffer, 1, MaxBuffer, fOrig);
|
||||
if (readLen > 0) {
|
||||
writeLen = fwrite(&buffer, 1, readLen, fDest);
|
||||
if (writeLen != readLen) {
|
||||
// Error
|
||||
fclose(fOrig);
|
||||
fclose(fDest);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}while(readLen==MaxBuffer);
|
||||
} while (readLen == MaxBuffer);
|
||||
|
||||
if(feof(fOrig)){
|
||||
ok=1;
|
||||
if (feof(fOrig)) {
|
||||
ok = 1;
|
||||
}
|
||||
|
||||
fclose(fOrig);
|
||||
|
||||
10
fileutil.h
10
fileutil.h
@@ -1,24 +1,21 @@
|
||||
#ifndef _FILEUTIL_
|
||||
#define _FILEUTIL_
|
||||
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// FileTime
|
||||
|
||||
typedef long long FileTime;
|
||||
|
||||
FileTime FileTime_Get(char *filename);
|
||||
void FileTime_Set(char *filename,FileTime t);
|
||||
void FileTime_Set(char *filename, FileTime t);
|
||||
void FileTime_Print(FileTime t);
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// File
|
||||
#define MaxPath 4096
|
||||
#define MaxFilename 512
|
||||
|
||||
void File_GetName(char *path,char *name);
|
||||
void File_GetName(char *path, char *name);
|
||||
|
||||
int File_ExistePath(char *path);
|
||||
|
||||
@@ -31,10 +28,9 @@ long long File_TamanhoFichero(char *ficheros);
|
||||
int File_CrearDir(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_BorrarDirectorio(char *path);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
288
main.c
288
main.c
@@ -8,246 +8,236 @@
|
||||
#include "filenode.h"
|
||||
#include "filenodecmp.h"
|
||||
|
||||
void help(char *exe){
|
||||
void help(char *exe) {
|
||||
char exeFilename[MaxPath];
|
||||
File_GetName(exe,exeFilename);
|
||||
File_GetName(exe, exeFilename);
|
||||
printf("Modo de uso:\n");
|
||||
printf(" %s info [file] {[file] {..}}\n",exeFilename);
|
||||
printf(" %s scan [dir] [tree] \n",exeFilename);
|
||||
printf(" %s rescan [dir] [tree] \n",exeFilename);
|
||||
printf(" %s read [file] [tree]\n",exeFilename);
|
||||
printf(" %s dir [dir]\n",exeFilename);
|
||||
printf(" %s info [file] {[file] {..}}\n", exeFilename);
|
||||
printf(" %s scan [dir] [tree] \n", exeFilename);
|
||||
printf(" %s rescan [dir] [tree] \n", exeFilename);
|
||||
printf(" %s read [file] [tree]\n", exeFilename);
|
||||
printf(" %s dir [dir]\n", exeFilename);
|
||||
printf("\n");
|
||||
printf(" %s sync [dirIzquierda] [dirDerecha]\n",exeFilename);
|
||||
printf(" %s resync [dirIzquierda] [dirDerecha]\n",exeFilename);
|
||||
printf(" %s synctest [dirIzquierda] [dirDerecha]\n",exeFilename);
|
||||
printf(" %s resynctest [dirIzquierda] [dirDerecha]\n",exeFilename);
|
||||
printf(" %s sync [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf(" %s resync [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf(" %s synctest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf(" %s resynctest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf("\n");
|
||||
printf(" %s copy [dirIzquierda] [dirDerecha]\n",exeFilename);
|
||||
printf(" %s recopy [dirIzquierda] [dirDerecha]\n",exeFilename);
|
||||
printf(" %s copytest [dirIzquierda] [dirDerecha]\n",exeFilename);
|
||||
printf(" %s recopytest [dirIzquierda] [dirDerecha]\n",exeFilename);
|
||||
printf(" %s copy [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf(" %s recopy [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf(" %s copytest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
printf(" %s recopytest [dirIzquierda] [dirDerecha]\n", exeFilename);
|
||||
}
|
||||
|
||||
FileNode *checkDir(char *path, int recheck);
|
||||
int sync(char *pathIzquierda, char *pathDerecha, int recheck, int dryrun);
|
||||
|
||||
FileNode *checkDir(char *path,int recheck);
|
||||
int sync(char *pathIzquierda,char *pathDerecha,int recheck,int dryrun);
|
||||
|
||||
|
||||
int main(int argc,char *argv[]){
|
||||
int main(int argc, char *argv[]) {
|
||||
FILE *f;
|
||||
unsigned long crc=0;
|
||||
unsigned long crc = 0;
|
||||
FileTime ft;
|
||||
int i;
|
||||
|
||||
if(argc<2){
|
||||
if (argc < 2) {
|
||||
help(argv[0]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!strcmp(argv[1],"info") && argc>=3){
|
||||
if (!strcmp(argv[1], "info") && argc >= 3) {
|
||||
// Informacion de ficheros
|
||||
for(i=2;i<argc;i++){
|
||||
if(File_ExistePath(argv[i])){
|
||||
f=fopen(argv[i],"rb");
|
||||
if(f){
|
||||
crc=CRC_File(f);
|
||||
for (i = 2; i < argc; i++) {
|
||||
if (File_ExistePath(argv[i])) {
|
||||
f = fopen(argv[i], "rb");
|
||||
if (f) {
|
||||
crc = CRC_File(f);
|
||||
fclose(f);
|
||||
}
|
||||
ft=FileTime_Get(argv[i]);
|
||||
printf("%s:\t[%08X]\t",argv[i],crc);
|
||||
FileTime_Print(ft);printf("\n");
|
||||
ft = FileTime_Get(argv[i]);
|
||||
printf("%s:\t[%08X]\t", argv[i], crc);
|
||||
FileTime_Print(ft);
|
||||
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
|
||||
FileNode *fn;
|
||||
printf("Building FileNode..\n");
|
||||
fn=FileNode_Build(argv[2]);
|
||||
FileNode_Save(fn,argv[3]);
|
||||
}else
|
||||
if(!strcmp(argv[1],"rescan") && argc==4){
|
||||
fn = FileNode_Build(argv[2]);
|
||||
FileNode_Save(fn, argv[3]);
|
||||
} else if (!strcmp(argv[1], "rescan") && argc == 4) {
|
||||
// Scanear informacion de directorio y guardar arbol
|
||||
FileNode *fn;
|
||||
printf("Loading FileNode..\n");
|
||||
fn=FileNode_Load(argv[3]);
|
||||
if(fn){
|
||||
fn = FileNode_Load(argv[3]);
|
||||
if (fn) {
|
||||
printf("Rebuilding FileNode..\n");
|
||||
fn=FileNode_Refresh(fn,argv[2]);
|
||||
FileNode_Save(fn,argv[3]);
|
||||
fn = FileNode_Refresh(fn, argv[2]);
|
||||
FileNode_Save(fn, argv[3]);
|
||||
}
|
||||
}else
|
||||
if(!strcmp(argv[1],"read") && argc==3){
|
||||
} else if (!strcmp(argv[1], "read") && argc == 3) {
|
||||
// Leer informacion de arbol
|
||||
FileNode *fn;
|
||||
fn=FileNode_Load(argv[2]);
|
||||
if(fn)FileNode_Print(fn);
|
||||
}else
|
||||
if(!strcmp(argv[1],"dir") && argc==3){
|
||||
fn = FileNode_Load(argv[2]);
|
||||
if (fn)
|
||||
FileNode_Print(fn);
|
||||
} else if (!strcmp(argv[1], "dir") && argc == 3) {
|
||||
// Leer informacion de dir
|
||||
char *path=argv[2];
|
||||
char *path = argv[2];
|
||||
char dirNodesFile[MaxPath];
|
||||
FileNode *fn;
|
||||
|
||||
fn=checkDir(path,1);
|
||||
if(fn){
|
||||
fn = checkDir(path, 1);
|
||||
if (fn) {
|
||||
FileNode_Print(fn);
|
||||
}
|
||||
}else
|
||||
if(!strcmp(argv[1],"sync") && argc==4){
|
||||
} 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){
|
||||
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){
|
||||
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){
|
||||
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);
|
||||
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
|
||||
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]);
|
||||
}
|
||||
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FileNode *checkDir(char *path,int recheck){
|
||||
FileNode *checkDir(char *path, int recheck) {
|
||||
char dirNodesFile[MaxPath];
|
||||
FileNode *fn;
|
||||
// Comprobar directorio
|
||||
snprintf(dirNodesFile,MaxPath,"%s/"FileNode_Filename,path);
|
||||
if(recheck){
|
||||
printf("Checking Directory.. %s\n",path);
|
||||
fn=FileNode_Load(dirNodesFile);
|
||||
if(fn){
|
||||
fn=FileNode_Refresh(fn,path);
|
||||
}else{
|
||||
fn=FileNode_Build(path);
|
||||
snprintf(dirNodesFile, MaxPath, "%s/"FileNode_Filename, path);
|
||||
if (recheck) {
|
||||
printf("Checking Directory.. %s\n", path);
|
||||
fn = FileNode_Load(dirNodesFile);
|
||||
if (fn) {
|
||||
fn = FileNode_Refresh(fn, path);
|
||||
} else {
|
||||
fn = FileNode_Build(path);
|
||||
}
|
||||
FileNode_Save(fn,dirNodesFile);
|
||||
}else{
|
||||
printf("Loading Directory.. %s\n",path);
|
||||
fn=FileNode_Load(dirNodesFile);
|
||||
if(!fn){
|
||||
FileNode_Save(fn, dirNodesFile);
|
||||
} else {
|
||||
printf("Loading Directory.. %s\n", path);
|
||||
fn = FileNode_Load(dirNodesFile);
|
||||
if (!fn) {
|
||||
printf("Error, no nodesFile.fs\n");
|
||||
return NULL;
|
||||
return NULL ;
|
||||
}
|
||||
}
|
||||
return fn;
|
||||
}
|
||||
|
||||
int sync(char *pathIzquierda,char *pathDerecha,int recheck,int dryrun){
|
||||
int sync(char *pathIzquierda, char *pathDerecha, int recheck, int dryrun) {
|
||||
char dirNodesFileIzq[MaxPath];
|
||||
char dirNodesFileDer[MaxPath];
|
||||
FileNode *fnIzquierda,*fnDerecha;
|
||||
FileNode *fnIzquierda, *fnDerecha;
|
||||
|
||||
// Comprobar y cargar directorios
|
||||
if(!File_ExistePath(pathIzquierda) || !File_EsDirectorio(pathIzquierda)){
|
||||
printf("Error, directory does not exist: %s\n",pathIzquierda);
|
||||
if (!File_ExistePath(pathIzquierda) || !File_EsDirectorio(pathIzquierda)) {
|
||||
printf("Error, directory does not exist: %s\n", pathIzquierda);
|
||||
return 0;
|
||||
}
|
||||
if(!File_ExistePath(pathDerecha) || !File_EsDirectorio(pathDerecha)){
|
||||
printf("Error, directory does not exist: %s\n",pathDerecha);
|
||||
if (!File_ExistePath(pathDerecha) || !File_EsDirectorio(pathDerecha)) {
|
||||
printf("Error, directory does not exist: %s\n", pathDerecha);
|
||||
return 0;
|
||||
}
|
||||
fnIzquierda = checkDir(pathIzquierda, recheck);
|
||||
if (!fnIzquierda) {
|
||||
return 0;
|
||||
}
|
||||
fnDerecha = checkDir(pathDerecha, recheck);
|
||||
if (!fnDerecha) {
|
||||
return 0;
|
||||
}
|
||||
fnIzquierda=checkDir(pathIzquierda,recheck);
|
||||
if(!fnIzquierda){return 0;}
|
||||
fnDerecha=checkDir(pathDerecha,recheck);
|
||||
if(!fnDerecha){return 0;}
|
||||
|
||||
|
||||
// Construir acciones
|
||||
printf("Building action list.. \n");
|
||||
AccionFileNode *afn=NULL;
|
||||
afn=AccionFileNode_BuildSync(fnIzquierda,fnDerecha);
|
||||
AccionFileNode *afn = NULL;
|
||||
afn = AccionFileNode_BuildSync(fnIzquierda, fnDerecha);
|
||||
|
||||
if(dryrun){
|
||||
if (dryrun) {
|
||||
// Mostrar lista de acciones
|
||||
AccionFileNode_Print(afn);
|
||||
}else{
|
||||
} else {
|
||||
// Ejecutar lista de acciones
|
||||
AccionFileNode_RunList(afn,pathIzquierda,pathDerecha);
|
||||
AccionFileNode_RunList(afn, pathIzquierda, pathDerecha);
|
||||
}
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int copy(char *pathIzquierda,char *pathDerecha,int recheck,int dryrun){
|
||||
int copy(char *pathIzquierda, char *pathDerecha, int recheck, int dryrun) {
|
||||
char dirNodesFileIzq[MaxPath];
|
||||
char dirNodesFileDer[MaxPath];
|
||||
FileNode *fnIzquierda,*fnDerecha;
|
||||
FileNode *fnIzquierda, *fnDerecha;
|
||||
|
||||
// Comprobar y cargar directorios
|
||||
if(!File_ExistePath(pathIzquierda) || !File_EsDirectorio(pathIzquierda)){
|
||||
printf("Error, directory does not exist: %s\n",pathIzquierda);
|
||||
if (!File_ExistePath(pathIzquierda) || !File_EsDirectorio(pathIzquierda)) {
|
||||
printf("Error, directory does not exist: %s\n", pathIzquierda);
|
||||
return 0;
|
||||
}
|
||||
if(!File_ExistePath(pathDerecha) || !File_EsDirectorio(pathDerecha)){
|
||||
printf("Error, directory does not exist: %s\n",pathDerecha);
|
||||
if (!File_ExistePath(pathDerecha) || !File_EsDirectorio(pathDerecha)) {
|
||||
printf("Error, directory does not exist: %s\n", pathDerecha);
|
||||
return 0;
|
||||
}
|
||||
fnIzquierda = checkDir(pathIzquierda, recheck);
|
||||
if (!fnIzquierda) {
|
||||
return 0;
|
||||
}
|
||||
fnDerecha = checkDir(pathDerecha, recheck);
|
||||
if (!fnDerecha) {
|
||||
return 0;
|
||||
}
|
||||
fnIzquierda=checkDir(pathIzquierda,recheck);
|
||||
if(!fnIzquierda){return 0;}
|
||||
fnDerecha=checkDir(pathDerecha,recheck);
|
||||
if(!fnDerecha){return 0;}
|
||||
|
||||
|
||||
// Construir acciones
|
||||
printf("Building action list.. \n");
|
||||
AccionFileNode *afn=NULL;
|
||||
afn=AccionFileNode_BuildCopy(fnIzquierda,fnDerecha);
|
||||
AccionFileNode *afn = NULL;
|
||||
afn = AccionFileNode_BuildCopy(fnIzquierda, fnDerecha);
|
||||
|
||||
if(dryrun){
|
||||
if (dryrun) {
|
||||
// Mostrar lista de acciones
|
||||
AccionFileNode_Print(afn);
|
||||
}else{
|
||||
} else {
|
||||
// Ejecutar lista de acciones
|
||||
AccionFileNode_RunList(afn,pathIzquierda,pathDerecha);
|
||||
AccionFileNode_RunList(afn, pathIzquierda, pathDerecha);
|
||||
}
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user