From ac3be0464df30621824f692165683c95e5e4efbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ca=C3=B1as=20Vargas?= Date: Mon, 21 Dec 2015 14:43:52 +0100 Subject: [PATCH] Version 15.70.7 --- swad_changelog.h | 3 +- swad_file_browser.c | 25 ++++++----- swad_web_service.c | 2 +- swad_zip.c | 104 +++++++++++++++++++++++--------------------- 4 files changed, 71 insertions(+), 63 deletions(-) diff --git a/swad_changelog.h b/swad_changelog.h index 965511fd..33be20b2 100644 --- a/swad_changelog.h +++ b/swad_changelog.h @@ -118,12 +118,13 @@ /****************************** Public constants *****************************/ /*****************************************************************************/ -#define Log_PLATFORM_VERSION "SWAD 15.70.6 (2015/12/21)" +#define Log_PLATFORM_VERSION "SWAD 15.70.7 (2015/12/21)" #define CSS_FILE "swad15.65.1.css" // Number of lines (includes comments but not blank lines) has been got with the following command: // nl swad*.c swad*.h css/swad*.css py/swad*.py js/swad*.js soap/swad*.h sql/swad*.sql | tail -1 /* + Version 15.70.7: Dec 21, 2015 Code refactoring in file browser. (187614 lines) Version 15.70.6: Dec 21, 2015 Removing old files in briefcase. Not finished. (187604 lines) 2 changes necessary in database: INSERT INTO actions (ActCod,Language,Obsolete,Txt) VALUES ('1488','es','N','Solicitar eliminar archivos antiguos maletín'); diff --git a/swad_file_browser.c b/swad_file_browser.c index d2e3efaf..dfd5b549 100644 --- a/swad_file_browser.c +++ b/swad_file_browser.c @@ -11428,9 +11428,9 @@ static void Brw_ScanDirRemovingOlfFiles (unsigned Level,const char *Path, else if (S_ISREG (FileStatus.st_mode) && // It's a regular file FileStatus.st_mtime < TimeRemoveFilesOlder) // ..and it's old { - /* Remove file */ - // if (unlink (PathFileRel)) - // Lay_ShowErrorAndExit ("Can not remove file / link."); + /* Remove file / link */ + if (unlink (PathFileRel)) + Lay_ShowErrorAndExit ("Can not remove file / link."); if (Str_FileIs (PathFileRel,"url")) (Removed->NumLinks)++; // It's a link (URL inside a .url file) @@ -11447,14 +11447,17 @@ static void Brw_ScanDirRemovingOlfFiles (unsigned Level,const char *Path, if (Level > 1) { /* Count number of files in folder */ - NumFiles = scandir (Path,&FileList,NULL,alphasort); - - /* Free list of files */ - for (NumFile = 0; - NumFile < NumFiles; - NumFile++) - free ((void *) FileList[NumFile]); - free ((void *) FileList); + if ((NumFiles = scandir (Path,&FileList,NULL,alphasort)) >= 0) // No error + { + /* Free list of files */ + for (NumFile = 0; + NumFile < NumFiles; + NumFile++) + free ((void *) FileList[NumFile]); + free ((void *) FileList); + } + else + Lay_ShowErrorAndExit ("Error while scanning directory."); } } diff --git a/swad_web_service.c b/swad_web_service.c index 9d78e001..bd5c77bb 100644 --- a/swad_web_service.c +++ b/swad_web_service.c @@ -91,7 +91,7 @@ cp -f /home/acanas/swad/swad/swad /var/www/cgi-bin/ /*****************************************************************************/ // In Eclipse, add to include path /usr/include, /usr/local/include, /usr/include/i386-linux-gnu -#include // For dirent +#include // For scandir, etc. #include // For PATH_MAX #include // For NULL #include // For setlocale, LC_NUMERIC... diff --git a/swad_zip.c b/swad_zip.c index ed965d69..343affad 100644 --- a/swad_zip.c +++ b/swad_zip.c @@ -470,9 +470,9 @@ static void ZIP_CompressFolderIntoZIP (void) static unsigned long long ZIP_CloneDir (const char *Path,const char *PathClone,const char *PathInTree) { - struct dirent **DirFileList; - int NumFileInThisDir; - int NumFilesInThisDir; + struct dirent **FileList; + int NumFile; + int NumFiles; char PathFile[PATH_MAX+1]; char PathFileClone[PATH_MAX+1]; char PathFileInTree[PATH_MAX+1]; @@ -489,60 +489,64 @@ static unsigned long long ZIP_CloneDir (const char *Path,const char *PathClone,c unsigned long long FullSize = 0; /***** Scan directory *****/ - NumFilesInThisDir = scandir (Path,&DirFileList,NULL,alphasort); + if ((NumFiles = scandir (Path,&FileList,NULL,alphasort)) >= 0) // No error + { + /***** List files *****/ + for (NumFile = 0; + NumFile < NumFiles; + NumFile++) + if (strcmp (FileList[NumFile]->d_name,".") && + strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".." + { + sprintf (PathFileInTree,"%s/%s", + PathInTree,FileList[NumFile]->d_name); + sprintf (PathFile,"%s/%s", + Path,FileList[NumFile]->d_name); + sprintf (PathFileClone,"%s/%s", + PathClone,FileList[NumFile]->d_name); - /***** List files *****/ - for (NumFileInThisDir = 0; - NumFileInThisDir < NumFilesInThisDir; - NumFileInThisDir++) - if (strcmp (DirFileList[NumFileInThisDir]->d_name,".") && - strcmp (DirFileList[NumFileInThisDir]->d_name,"..")) // Skip directories "." and ".." - { - sprintf (PathFileInTree,"%s/%s",PathInTree,DirFileList[NumFileInThisDir]->d_name); - sprintf (PathFile,"%s/%s", - Path,DirFileList[NumFileInThisDir]->d_name); - sprintf (PathFileClone,"%s/%s", - PathClone,DirFileList[NumFileInThisDir]->d_name); + lstat (PathFile,&FileStatus); + if (S_ISDIR (FileStatus.st_mode)) // It's a directory + FileType = Brw_IS_FOLDER; + else if (S_ISREG (FileStatus.st_mode)) // It's a regular file + FileType = Str_FileIs (FileList[NumFile]->d_name,"url") ? Brw_IS_LINK : // It's a link (URL inside a .url file) + Brw_IS_FILE; // It's a file + else + FileType = Brw_IS_UNKNOWN; - lstat (PathFile,&FileStatus); - if (S_ISDIR (FileStatus.st_mode)) // It's a directory - FileType = Brw_IS_FOLDER; - else if (S_ISREG (FileStatus.st_mode)) // It's a regular file - FileType = Str_FileIs (DirFileList[NumFileInThisDir]->d_name,"url") ? Brw_IS_LINK : // It's a link (URL inside a .url file) - Brw_IS_FILE; // It's a file - else - FileType = Brw_IS_UNKNOWN; + Hidden = (SeeDocsZone || SeeMarks) ? Brw_CheckIfFileOrFolderIsSetAsHiddenInDB (FileType,PathFileInTree) : + false; - Hidden = (SeeDocsZone || SeeMarks) ? Brw_CheckIfFileOrFolderIsSetAsHiddenInDB (FileType,PathFileInTree) : - false; - - if (!Hidden) // If file/folder is not hidden - { - if (FileType == Brw_IS_FOLDER) // It's a directory + if (!Hidden) // If file/folder is not hidden { - FullSize += (unsigned long long) FileStatus.st_size; + if (FileType == Brw_IS_FOLDER) // It's a directory + { + FullSize += (unsigned long long) FileStatus.st_size; - /***** Create clone of subdirectory *****/ - if (mkdir (PathFileClone,(mode_t) 0xFFF)) - Lay_ShowErrorAndExit ("Can not create temporary subfolder for compression."); + /***** Create clone of subdirectory *****/ + if (mkdir (PathFileClone,(mode_t) 0xFFF)) + Lay_ShowErrorAndExit ("Can not create temporary subfolder for compression."); - /***** Clone subtree starting at this this directory *****/ - FullSize += ZIP_CloneDir (PathFile,PathFileClone,PathFileInTree); + /***** Clone subtree starting at this this directory *****/ + FullSize += ZIP_CloneDir (PathFile,PathFileClone,PathFileInTree); + } + else if (FileType == Brw_IS_FILE || + FileType == Brw_IS_LINK) // It's a regular file + { + FullSize += (unsigned long long) FileStatus.st_size; + + /***** Create a symbolic link (clone) to original file *****/ + if (symlink (PathFile,PathFileClone) != 0) + Lay_ShowErrorAndExit ("Can not create temporary link for compression."); + + /***** Update number of my views of this file *****/ + Brw_UpdateMyFileViews (Brw_GetFilCodByPath (PathFileInTree)); + } } - else if (FileType == Brw_IS_FILE || - FileType == Brw_IS_LINK) // It's a regular file - { - FullSize += (unsigned long long) FileStatus.st_size; - - /***** Create a symbolic link (clone) to original file *****/ - if (symlink (PathFile,PathFileClone) != 0) - Lay_ShowErrorAndExit ("Can not create temporary link for compression."); - - /***** Update number of my views of this file *****/ - Brw_UpdateMyFileViews (Brw_GetFilCodByPath (PathFileInTree)); - } - } - } + } + } + else + Lay_ShowErrorAndExit ("Error while scanning directory."); return FullSize; }