Fix: FAT32 modification date is inexact (+-1sec)

Show clearly the action in the console.
This commit is contained in:
2013-06-07 00:17:32 +02:00
parent 4e0ba1e714
commit f4f668d82f
3 changed files with 30 additions and 48 deletions

View File

@@ -36,7 +36,6 @@ AccionFileNode *AccionFileNode_Crear(){
afn->izquierda=NULL; afn->izquierda=NULL;
afn->derecha=NULL; afn->derecha=NULL;
afn->sig=NULL; afn->sig=NULL;
afn->motivo[0]=0;
return(afn); return(afn);
} }
@@ -159,7 +158,6 @@ void AccionFileNode_DeletePair(
if(fnDer->estado!=EstadoFichero_Borrado){ if(fnDer->estado!=EstadoFichero_Borrado){
// Accion de borrado para el nodo // Accion de borrado para el nodo
afnNew->accion=AccionFileCmp_BorrarDerecha; afnNew->accion=AccionFileCmp_BorrarDerecha;
strcpy(afnNew->motivo,"DEL: solo existe Der");
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
}else{ }else{
@@ -176,7 +174,6 @@ void AccionFileNode_DeletePair(
if(fnIzq->estado!=EstadoFichero_Borrado){ if(fnIzq->estado!=EstadoFichero_Borrado){
// Accion de borrado para el nodo // Accion de borrado para el nodo
afnNew->accion=AccionFileCmp_BorrarIzquierda; afnNew->accion=AccionFileCmp_BorrarIzquierda;
strcpy(afnNew->motivo,"DEL: solo existe Izq");
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
}else{ }else{
@@ -197,7 +194,6 @@ void AccionFileNode_DeletePair(
if(fnIzq->estado!=EstadoFichero_Borrado){ if(fnIzq->estado!=EstadoFichero_Borrado){
// Accion de borrado para el nodo izquierdo // Accion de borrado para el nodo izquierdo
afnNew->accion=AccionFileCmp_BorrarIzquierda; afnNew->accion=AccionFileCmp_BorrarIzquierda;
strcpy(afnNew->motivo,"DEL: existe Izq");
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
afnNew=NULL; afnNew=NULL;
@@ -206,7 +202,6 @@ void AccionFileNode_DeletePair(
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;
strcpy(afnNew->motivo,"DEL: existe Der");
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
afnNew=NULL; afnNew=NULL;
@@ -233,7 +228,6 @@ void AccionFileNode_CheckPair(
afnNew->accion=AccionFileCmp_Nada; afnNew->accion=AccionFileCmp_Nada;
// Anhadir a la lista de acciones // Anhadir a la lista de acciones
strcpy(afnNew->motivo,"CMP: nada, solo der borrada");
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
@@ -241,7 +235,6 @@ void AccionFileNode_CheckPair(
afnNew->accion=AccionFileCmp_CrearDirIzquierda; afnNew->accion=AccionFileCmp_CrearDirIzquierda;
// Anhadir a la lista de acciones // Anhadir a la lista de acciones
strcpy(afnNew->motivo,"CMP: dir izquierdo no existe");
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
@@ -252,7 +245,6 @@ void AccionFileNode_CheckPair(
// Crear nueva accion para copiar la fecha // Crear nueva accion para copiar la fecha
afnNew=AccionFileNode_CrearNormal(fnIzq,fnDer); afnNew=AccionFileNode_CrearNormal(fnIzq,fnDer);
afnNew->accion=AccionFileCmp_FechaDerechaAIzquierda; afnNew->accion=AccionFileCmp_FechaDerechaAIzquierda;
strcpy(afnNew->motivo,"CMP: dir izquierdo no existe");
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
} }
@@ -260,10 +252,8 @@ void AccionFileNode_CheckPair(
// File // File
if(fnDer->estado==EstadoFichero_Borrado){ if(fnDer->estado==EstadoFichero_Borrado){
afnNew->accion=AccionFileCmp_Nada; afnNew->accion=AccionFileCmp_Nada;
strcpy(afnNew->motivo,"CMP: nada, solo der borrada");
}else{ }else{
afnNew->accion=AccionFileCmp_DerechaAIzquierda; afnNew->accion=AccionFileCmp_DerechaAIzquierda;
strcpy(afnNew->motivo,"CMP: solo existe der");
} }
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
@@ -276,7 +266,6 @@ void AccionFileNode_CheckPair(
afnNew->accion=AccionFileCmp_Nada; afnNew->accion=AccionFileCmp_Nada;
// Anhadir a la lista de acciones // Anhadir a la lista de acciones
strcpy(afnNew->motivo,"CMP: nada, solo izq borrada");
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
@@ -284,7 +273,6 @@ void AccionFileNode_CheckPair(
afnNew->accion=AccionFileCmp_CrearDirDerecha; afnNew->accion=AccionFileCmp_CrearDirDerecha;
// Anhadir a la lista de acciones // Anhadir a la lista de acciones
strcpy(afnNew->motivo,"CMP: dir der no existe");
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
@@ -295,7 +283,6 @@ void AccionFileNode_CheckPair(
// Crear nueva accion para copiar la fecha // Crear nueva accion para copiar la fecha
afnNew=AccionFileNode_CrearNormal(fnIzq,fnDer); afnNew=AccionFileNode_CrearNormal(fnIzq,fnDer);
afnNew->accion=AccionFileCmp_FechaIzquierdaADerecha; afnNew->accion=AccionFileCmp_FechaIzquierdaADerecha;
strcpy(afnNew->motivo,"CMP: dir der no existe");
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
} }
@@ -303,10 +290,8 @@ void AccionFileNode_CheckPair(
// File // File
if(fnIzq->estado==EstadoFichero_Borrado){ if(fnIzq->estado==EstadoFichero_Borrado){
afnNew->accion=AccionFileCmp_Nada; afnNew->accion=AccionFileCmp_Nada;
strcpy(afnNew->motivo,"CMP: nada, solo izq borrada");
}else{ }else{
afnNew->accion=AccionFileCmp_IzquierdaADerecha; afnNew->accion=AccionFileCmp_IzquierdaADerecha;
strcpy(afnNew->motivo,"CMP: solo existe der");
} }
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
@@ -319,7 +304,7 @@ void AccionFileNode_CheckPair(
// Directorios // Directorios
// Preparar accion para el par de directorios // Preparar accion para el par de directorios
if(fnIzq->ft==fnDer->ft){ 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)
{ {
@@ -374,7 +359,6 @@ void AccionFileNode_CheckPair(
} }
// Encolar accion para el directorio padre // Encolar accion para el directorio padre
strcpy(afnNew->motivo,"CMP: dir cmp");
(*afnCola)->sig=afnNew; (*afnCola)->sig=afnNew;
(*afnCola)=afnNew; (*afnCola)=afnNew;
@@ -408,8 +392,6 @@ void AccionFileNode_CheckPair(
} }
}else }else
if(fnIzq->ft<fnDer->ft){ if(fnIzq->ft<fnDer->ft){
//strcpy(afnNew->motivo,"CMP: izq<der");
sprintf(afnNew->motivo,"i:%lld < d:%lld",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;
@@ -419,8 +401,6 @@ void AccionFileNode_CheckPair(
} }
}else }else
if(fnIzq->ft>fnDer->ft){ if(fnIzq->ft>fnDer->ft){
//strcpy(afnNew->motivo,"CMP: der<izq");
sprintf(afnNew->motivo,"d:%lld < i:%lld",fnDer->ft,fnIzq->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;
@@ -458,17 +438,12 @@ AccionFileNode *AccionFileNode_Build(
void AccionFileNode_Print(AccionFileNode *afn){ void AccionFileNode_Print(AccionFileNode *afn){
char pathIzq[MaxPath],pathDer[MaxPath]; char showPath[MaxPath];
while(afn!=NULL){ while(afn!=NULL){
if(afn->izquierda){ if(afn->izquierda){
FileNode_GetPath(afn->izquierda,pathIzq); FileNode_GetFullPath(afn->izquierda,"",showPath);
}else{ }else{
strcpy(pathIzq,"(null)"); FileNode_GetFullPath(afn->derecha,"",showPath);
}
if(afn->derecha){
FileNode_GetPath(afn->derecha,pathDer);
}else{
strcpy(pathDer,"(null)");
} }
switch(afn->accion){ switch(afn->accion){
@@ -476,21 +451,21 @@ 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 => %s %s\n",pathIzq,pathDer,afn->motivo);break; printf(" => %s\n",showPath);break;
case AccionFileCmp_DerechaAIzquierda: case AccionFileCmp_DerechaAIzquierda:
printf("%s <= %s %s\n",pathIzq,pathDer,afn->motivo);break; printf(" <= %s\n",showPath);break;
case AccionFileCmp_BorrarIzquierda: case AccionFileCmp_BorrarIzquierda:
printf("%s *- %s %s\n",pathIzq,pathDer,afn->motivo);break; printf(" *- %s\n",showPath);break;
case AccionFileCmp_BorrarDerecha: case AccionFileCmp_BorrarDerecha:
printf("%s -* %s %s\n",pathIzq,pathDer,afn->motivo);break; printf(" -* %s\n",showPath);break;
case AccionFileCmp_FechaIzquierdaADerecha: case AccionFileCmp_FechaIzquierdaADerecha:
printf("%s -> %s %s\n",pathIzq,pathDer,afn->motivo);break; printf(" -> %s\n",showPath);break;
case AccionFileCmp_FechaDerechaAIzquierda: case AccionFileCmp_FechaDerechaAIzquierda:
printf("%s <- %s %s\n",pathIzq,pathDer,afn->motivo);break; printf(" <- %s\n",showPath);break;
case AccionFileCmp_CrearDirDerecha: case AccionFileCmp_CrearDirDerecha:
printf("%s -D %s %s\n",pathIzq,pathDer,afn->motivo);break; printf(" -D %s\n",showPath);break;
case AccionFileCmp_CrearDirIzquierda: case AccionFileCmp_CrearDirIzquierda:
printf("%s D- %s %s\n",pathIzq,pathDer,afn->motivo);break; printf(" D- %s\n",showPath);break;
} }
afn=afn->sig; afn=afn->sig;
@@ -510,6 +485,8 @@ void AccionFileNodeAux_CopyDate(char *pathOrig,char *pathDest){
void AccionFileNodeAux_Copy(char *pathOrig,char *pathDest){ void AccionFileNodeAux_Copy(char *pathOrig,char *pathDest){
if(File_Copiar(pathOrig,pathDest)){ if(File_Copiar(pathOrig,pathDest)){
AccionFileNodeAux_CopyDate(pathOrig,pathDest); AccionFileNodeAux_CopyDate(pathOrig,pathDest);
}else{
File_Borrar(pathDest);
} }
} }
void AccionFileNodeAux_Delete(char *pathOrig,char *pathDest){ void AccionFileNodeAux_Delete(char *pathOrig,char *pathDest){
@@ -524,7 +501,7 @@ void AccionFileNodeAux_MakeDir(char *pathOrig,char *pathDest){
} }
void AccionFileNode_RunList(AccionFileNode *afn,char *pathIzquierda,char *pathDerecha){ void AccionFileNode_RunList(AccionFileNode *afn,char *pathIzquierda,char *pathDerecha){
char pathIzq[MaxPath],pathDer[MaxPath]; char pathIzq[MaxPath],pathDer[MaxPath],showPath[MaxPath];
while(afn!=NULL){ while(afn!=NULL){
if(afn->izquierda){ if(afn->izquierda){
FileNode_GetFullPath(afn->izquierda,pathIzquierda,pathIzq); FileNode_GetFullPath(afn->izquierda,pathIzquierda,pathIzq);
@@ -536,41 +513,47 @@ void AccionFileNode_RunList(AccionFileNode *afn,char *pathIzquierda,char *pathDe
}else{ }else{
FileNode_GetFullPath(afn->izquierda,pathDerecha,pathDer); FileNode_GetFullPath(afn->izquierda,pathDerecha,pathDer);
} }
if(afn->izquierda){
FileNode_GetFullPath(afn->izquierda,"",showPath);
}else{
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);
break; break;
case AccionFileCmp_IzquierdaADerecha: case AccionFileCmp_IzquierdaADerecha:
printf("%s => %s\n",pathIzq,pathDer); printf(" => %s\n",showPath);
AccionFileNodeAux_Copy(pathIzq,pathDer); AccionFileNodeAux_Copy(pathIzq,pathDer);
break; break;
case AccionFileCmp_DerechaAIzquierda: case AccionFileCmp_DerechaAIzquierda:
printf("%s <= %s\n",pathIzq,pathDer); printf(" <= %s\n",showPath);
AccionFileNodeAux_Copy(pathDer,pathIzq); AccionFileNodeAux_Copy(pathDer,pathIzq);
break; break;
case AccionFileCmp_BorrarIzquierda: case AccionFileCmp_BorrarIzquierda:
printf("%s *- %s\n",pathIzq,pathDer); printf(" *- %s\n",showPath);
AccionFileNodeAux_Delete(pathDer,pathIzq); AccionFileNodeAux_Delete(pathDer,pathIzq);
break; break;
case AccionFileCmp_BorrarDerecha: case AccionFileCmp_BorrarDerecha:
printf("%s -* %s\n",pathIzq,pathDer); printf(" -* %s\n",showPath);
AccionFileNodeAux_Delete(pathIzq,pathDer); AccionFileNodeAux_Delete(pathIzq,pathDer);
break; break;
case AccionFileCmp_FechaIzquierdaADerecha: case AccionFileCmp_FechaIzquierdaADerecha:
printf("%s -> %s\n",pathIzq,pathDer); printf(" -> %s\n",showPath);
AccionFileNodeAux_CopyDate(pathIzq,pathDer); AccionFileNodeAux_CopyDate(pathIzq,pathDer);
break; break;
case AccionFileCmp_FechaDerechaAIzquierda: case AccionFileCmp_FechaDerechaAIzquierda:
printf("%s <- %s\n",pathIzq,pathDer); printf(" <- %s\n",showPath);
AccionFileNodeAux_CopyDate(pathDer,pathIzq); AccionFileNodeAux_CopyDate(pathDer,pathIzq);
break; break;
case AccionFileCmp_CrearDirDerecha: case AccionFileCmp_CrearDirDerecha:
printf("%s -D %s\n",pathIzq,pathDer); printf(" -D %s\n",showPath);
AccionFileNodeAux_MakeDir(pathIzq,pathDer); AccionFileNodeAux_MakeDir(pathIzq,pathDer);
break; break;
case AccionFileCmp_CrearDirIzquierda: case AccionFileCmp_CrearDirIzquierda:
printf("%s D- %s\n",pathIzq,pathDer); printf(" D- %s\n",showPath);
AccionFileNodeAux_MakeDir(pathDer,pathIzq); AccionFileNodeAux_MakeDir(pathDer,pathIzq);
break; break;
} }

View File

@@ -22,7 +22,6 @@ typedef struct Tag_AccionFileNode {
FileNode *izquierda; FileNode *izquierda;
FileNode *derecha; FileNode *derecha;
struct Tag_AccionFileNode *sig; struct Tag_AccionFileNode *sig;
char motivo[128];
} AccionFileNode; } AccionFileNode;

View File

@@ -68,7 +68,7 @@ FileTime FileTime_Get(char *filename){
void FileTime_Set(char *filename,FileTime t){ void FileTime_Set(char *filename,FileTime t){
HANDLE hFile; HANDLE hFile;
FILETIME ftWrite; FILETIME ftWrite;
hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
ftWrite=POSIX_to_FileTime(t); ftWrite=POSIX_to_FileTime(t);
SetFileTime(hFile, NULL, NULL, &ftWrite); SetFileTime(hFile, NULL, NULL, &ftWrite);