diff --git a/src/actionfilenode.c b/src/actionfilenode.c index f87d01c..89e9ceb 100644 --- a/src/actionfilenode.c +++ b/src/actionfilenode.c @@ -250,19 +250,23 @@ void AccionFileNodeAux_Copy(char *pathOrig, char *pathDest) { AccionFileNodeAux_CopyDate(pathOrig, pathDest); } else { File_Delete(pathDest); - Print("Error Copying to: %s\n", pathDest); + Print("Error Copying to: %s, %s\n", pathDest, GetError()); } } void AccionFileNodeAux_Delete(char *pathOrig, char *pathDest) { if (File_IsDirectory(pathDest)) { - File_DeleteDirectory(pathDest); + if (File_DeleteDirectory(pathDest)) { + Print("Error Deleting Directory: %s, %s\n", pathDest, GetError()); + } } else { - File_Delete(pathDest); + if (File_Delete(pathDest)) { + Print("Error Deleting File: %s, %s\n", pathDest, GetError()); + } } } void AccionFileNodeAux_MakeDir(char *pathOrig, char *pathDest) { if (File_MakeDirectory(pathDest) == 0) { - Print("Error Making Directory: %s\n", pathDest); + Print("Error Making Directory: %s, %s\n", pathDest, GetError()); } } diff --git a/src/fileutil.c b/src/fileutil.c index cb6b594..cb83b42 100644 --- a/src/fileutil.c +++ b/src/fileutil.c @@ -10,6 +10,7 @@ #include #include #include +#include #else #include #include @@ -19,6 +20,7 @@ #include #include #include +#include #endif #include "util.h" @@ -200,6 +202,7 @@ int File_ExistsPath(char *path) { rc = GetFileAttributes(path); if (rc == INVALID_FILE_ATTRIBUTES) { + SetError(strerror(errno)); return (0); } return (1); @@ -209,6 +212,7 @@ int File_IsDirectory(char *fileName) { rc = GetFileAttributes(fileName); if (rc == INVALID_FILE_ATTRIBUTES) { + SetError(strerror(errno)); return (0); } if (rc & FILE_ATTRIBUTE_DIRECTORY) { @@ -221,6 +225,7 @@ int File_IsFile(char *fileName) { rc = GetFileAttributes(fileName); if (rc == INVALID_FILE_ATTRIBUTES) { + SetError(strerror(errno)); return (0); } if (rc & FILE_ATTRIBUTE_DIRECTORY) { @@ -242,6 +247,7 @@ int File_IsDirectory(char *fileName) { struct stat info; if (lstat(fileName, &info) == -1) { + SetError(strerror(errno)); return (0); } if (S_ISDIR(info.st_mode)) { @@ -253,6 +259,7 @@ int File_IsFile(char *fileName) { struct stat info; if (lstat(fileName, &info) == -1) { + SetError(strerror(errno)); return (0); } if (S_ISDIR(info.st_mode)) { @@ -265,7 +272,14 @@ int File_IsFile(char *fileName) { #ifdef WIN32 int File_MakeDirectory(char *path) { return (CreateDirectory(path, NULL)); } #else -int File_MakeDirectory(char *path) { return (mkdir(path, 0777)); } +int File_MakeDirectory(char *path) { + int rc = mkdir(path, 0777); + if (rc != 0) { + SetError(strerror(errno)); + return 0; + } + return 1; +} #endif #ifdef WIN32 @@ -328,20 +342,30 @@ void File_IterateDir(char *path, } #endif -void File_Delete(char *path) { +int File_Delete(char *path) { #ifdef WIN32 - remove(path); + int rc = remove(path); #else - unlink(path); + int rc = unlink(path); #endif + if (rc != 0) { + SetError(strerror(errno)); + return 0; + } + return 1; } -void File_DeleteDirectory(char *path) { +int File_DeleteDirectory(char *path) { #ifndef WIN32 - rmdir(path); + int rc = rmdir(path); #else - _rmdir(path); + int rc = _rmdir(path); #endif + if (rc != 0) { + SetError(strerror(errno)); + return 0; + } + return 1; } #define MaxBuffer 16384 @@ -354,9 +378,11 @@ int File_Copy(const char *pathOrig, const char *pathDest) { int status = 0; if ((fOrig = fopen(pathOrig, "rb")) == NULL) { + SetError(strerror(errno)); goto cleanup; } if ((fDest = fopen(pathDest, "wb")) == NULL) { + SetError(strerror(errno)); goto cleanup; } @@ -370,8 +396,7 @@ int File_Copy(const char *pathOrig, const char *pathDest) { if (readLen > 0) { writeLen = fwrite(buffer, 1, readLen, fDest); if (writeLen != readLen) { - // Write error - status = -1; + SetError("Write error"); goto cleanup; } } diff --git a/src/fileutil.h b/src/fileutil.h index a3f04e2..fc2d973 100644 --- a/src/fileutil.h +++ b/src/fileutil.h @@ -48,8 +48,8 @@ void File_IterateDir(char *path, int (*func)(char *path, char *name, void *data), void *data); -void File_Delete(char *path); -void File_DeleteDirectory(char *path); +int File_Delete(char *path); +int File_DeleteDirectory(char *path); int File_Copy(const char *pathOrig, const char *pathDest); diff --git a/src/util.c b/src/util.c index b19db2c..0febe49 100644 --- a/src/util.c +++ b/src/util.c @@ -154,4 +154,17 @@ int Print(char *fmt, ...) { // Flush fflush(stdout); return (n); -} \ No newline at end of file +} + +///////////////////////////// +// SetError +// GetError +// +char _errorMessage[2048] = ""; +char _errorMessageTemp[2048] = ""; +void SetError(char *msg) { strcpy(_errorMessage, msg); } +char *GetError() { + strcpy(_errorMessageTemp, _errorMessage); + strcpy(_errorMessage, ""); + return _errorMessageTemp; +} diff --git a/src/util.h b/src/util.h index 4dca249..5e7cee0 100644 --- a/src/util.h +++ b/src/util.h @@ -46,4 +46,11 @@ int PrintDataSize(long long size); // Prints the formated text screen int Print(char *fmt, ...); +///////////////////////////// +// SetError +// GetError +// +void SetError(char *msg); +char *GetError(); + #endif