Version 15.70.5

This commit is contained in:
Antonio Cañas Vargas 2015-12-21 13:36:39 +01:00
parent 5ef7ba86e8
commit e89f26fd49
4 changed files with 368 additions and 296 deletions

View File

@ -118,12 +118,14 @@
/****************************** Public constants *****************************/ /****************************** Public constants *****************************/
/*****************************************************************************/ /*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 15.70.3 (2015/12/21)" #define Log_PLATFORM_VERSION "SWAD 15.70.5 (2015/12/21)"
#define CSS_FILE "swad15.65.1.css" #define CSS_FILE "swad15.65.1.css"
// Number of lines (includes comments but not blank lines) has been got with the following command: // 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 // 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.5: Dec 21, 2015 Code refactoring in file browser. (187569 lines)
Version 15.70.4: Dec 21, 2015 Code refactoring in file browser. (187527 lines)
Version 15.70.3: Dec 21, 2015 Code refactoring in file browser. (187490 lines) Version 15.70.3: Dec 21, 2015 Code refactoring in file browser. (187490 lines)
Version 15.70.2: Dec 21, 2015 Users can selected number of months in form to remove old files in briefcase. Not finished. (187473 lines) Version 15.70.2: Dec 21, 2015 Users can selected number of months in form to remove old files in briefcase. Not finished. (187473 lines)
Version 15.70.1: Dec 21, 2015 Removing old files in briefcase. Not finished. (187408 lines) Version 15.70.1: Dec 21, 2015 Removing old files in briefcase. Not finished. (187408 lines)

View File

@ -415,7 +415,8 @@ void Fil_CreateDirIfNotExists (const char *Path)
void Fil_RemoveOldTmpFiles (const char *Path,time_t TimeToRemove,bool RemoveDirectory) void Fil_RemoveOldTmpFiles (const char *Path,time_t TimeToRemove,bool RemoveDirectory)
{ {
struct dirent **FileList; struct dirent **FileList;
int NumFile,NumFilesInsideDir; int NumFile;
int NumFiles;
char Path2[PATH_MAX+1]; char Path2[PATH_MAX+1];
struct stat FileStatus; struct stat FileStatus;
@ -423,25 +424,33 @@ void Fil_RemoveOldTmpFiles (const char *Path,time_t TimeToRemove,bool RemoveDire
if (S_ISDIR (FileStatus.st_mode)) // It's a directory if (S_ISDIR (FileStatus.st_mode)) // It's a directory
{ {
/***** Scan the directory *****/ /***** Scan the directory *****/
NumFilesInsideDir = scandir (Path,&FileList,NULL,NULL); if ((NumFiles = scandir (Path,&FileList,NULL,NULL)) >= 0) // No error
{
/* Loop over files */ /* Loop over files */
for (NumFile = 0; for (NumFile = 0;
NumFile < NumFilesInsideDir; NumFile < NumFiles;
NumFile++) NumFile++)
{
if (strcmp (FileList[NumFile]->d_name,".") && if (strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".." strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{ {
sprintf (Path2,"%s/%s",Path,FileList[NumFile]->d_name); sprintf (Path2,"%s/%s",Path,FileList[NumFile]->d_name);
Fil_RemoveOldTmpFiles (Path2,TimeToRemove,true); // Recursive call Fil_RemoveOldTmpFiles (Path2,TimeToRemove,true); // Recursive call
} }
free ((void *) FileList[NumFile]);
}
free ((void *) FileList);
if (RemoveDirectory) if (RemoveDirectory)
/* Remove the directory itself */ /* Remove the directory itself */
if (Gbl.StartExecutionTimeUTC - FileStatus.st_mtime > TimeToRemove) if (FileStatus.st_mtime < Gbl.StartExecutionTimeUTC - TimeToRemove)
rmdir (Path); rmdir (Path);
} }
else else
if (Gbl.StartExecutionTimeUTC - FileStatus.st_mtime > TimeToRemove) Lay_ShowErrorAndExit ("Error while scanning directory.");
}
else
if (FileStatus.st_mtime < Gbl.StartExecutionTimeUTC - TimeToRemove)
unlink (Path); unlink (Path);
} }

View File

@ -4612,28 +4612,28 @@ void Brw_CalcSizeOfDir (char *Path)
static void Brw_CalcSizeOfDirRecursive (unsigned Level,char *Path) static void Brw_CalcSizeOfDirRecursive (unsigned Level,char *Path)
{ {
struct dirent **FileList; struct dirent **FileList;
int NumFileInThisDir; int NumFile;
int NumFilesInThisDir; int NumFiles;
char PathFileRel[PATH_MAX+1]; char PathFileRel[PATH_MAX+1];
struct stat FileStatus; struct stat FileStatus;
/***** Scan the directory *****/ /***** Scan the directory *****/
NumFilesInThisDir = scandir (Path,&FileList,NULL,NULL); if ((NumFiles = scandir (Path,&FileList,NULL,NULL)) >= 0) // No error
/***** Compute recursively the total number and size of the files and folders *****/
for (NumFileInThisDir = 0;
NumFileInThisDir < NumFilesInThisDir;
NumFileInThisDir++)
{ {
if (strcmp (FileList[NumFileInThisDir]->d_name,".") && /***** Compute recursively the total number and size of the files and folders *****/
strcmp (FileList[NumFileInThisDir]->d_name,"..")) // Skip directories "." and ".." for (NumFile = 0;
NumFile < NumFiles;
NumFile++)
{
if (strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{ {
/* There are files in this directory ==> update level */ /* There are files in this directory ==> update level */
if (Level > Gbl.FileBrowser.Size.NumLevls) if (Level > Gbl.FileBrowser.Size.NumLevls)
Gbl.FileBrowser.Size.NumLevls++; Gbl.FileBrowser.Size.NumLevls++;
/* Update counters depending on whether it's a directory or a regular file */ /* Update counters depending on whether it's a directory or a regular file */
sprintf (PathFileRel,"%s/%s",Path,FileList[NumFileInThisDir]->d_name); sprintf (PathFileRel,"%s/%s",Path,FileList[NumFile]->d_name);
lstat (PathFileRel,&FileStatus); lstat (PathFileRel,&FileStatus);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory if (S_ISDIR (FileStatus.st_mode)) // It's a directory
{ {
@ -4647,9 +4647,12 @@ static void Brw_CalcSizeOfDirRecursive (unsigned Level,char *Path)
Gbl.FileBrowser.Size.TotalSiz += (unsigned long long) FileStatus.st_size; Gbl.FileBrowser.Size.TotalSiz += (unsigned long long) FileStatus.st_size;
} }
} }
free (FileList[NumFileInThisDir]); free ((void *) FileList[NumFile]);
} }
free (FileList); free ((void *) FileList);
}
else
Lay_ShowErrorAndExit ("Error while scanning directory.");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -4658,33 +4661,35 @@ static void Brw_CalcSizeOfDirRecursive (unsigned Level,char *Path)
static void Brw_ListDir (unsigned Level,const char *Path,const char *PathInTree) static void Brw_ListDir (unsigned Level,const char *Path,const char *PathInTree)
{ {
struct dirent **DirFileList; struct dirent **FileList;
struct dirent **SubdirFileList; struct dirent **SubdirFileList;
int NumFileInThisDir; int NumFile;
int NumFilesInThisDir; int NumFiles;
int NumFilesInThisSubdir; int NumFileInSubdir;
int NumFilesInSubdir;
char PathFileRel[PATH_MAX+1]; char PathFileRel[PATH_MAX+1];
char PathFileInExplTree[PATH_MAX+1]; char PathFileInExplTree[PATH_MAX+1];
struct stat FileStatus; struct stat FileStatus;
Brw_ExpandTree_t ExpandTree; Brw_ExpandTree_t ExpandTree = Brw_EXPAND_TREE_NOTHING; // Initialized to avoid warning
/***** Scan directory *****/ /***** Scan directory *****/
NumFilesInThisDir = scandir (Path,&DirFileList,NULL,alphasort); if ((NumFiles = scandir (Path,&FileList,NULL,alphasort)) >= 0) // No error
/***** List files *****/
for (NumFileInThisDir = 0;
NumFileInThisDir < NumFilesInThisDir;
NumFileInThisDir++)
if (strcmp (DirFileList[NumFileInThisDir]->d_name,".") &&
strcmp (DirFileList[NumFileInThisDir]->d_name,"..")) // Skip directories "." and ".."
{ {
sprintf (PathFileRel ,"%s/%s",Path ,DirFileList[NumFileInThisDir]->d_name); /***** List files *****/
sprintf (PathFileInExplTree,"%s/%s",PathInTree,DirFileList[NumFileInThisDir]->d_name); for (NumFile = 0;
NumFile < NumFiles;
NumFile++)
{
if (strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{
sprintf (PathFileRel ,"%s/%s",Path ,FileList[NumFile]->d_name);
sprintf (PathFileInExplTree,"%s/%s",PathInTree,FileList[NumFile]->d_name);
lstat (PathFileRel,&FileStatus); lstat (PathFileRel,&FileStatus);
/***** Construct the full path of the file or folder *****/ /***** Construct the full path of the file or folder *****/
Brw_SetFullPathInTree (PathInTree,DirFileList[NumFileInThisDir]->d_name); Brw_SetFullPathInTree (PathInTree,FileList[NumFile]->d_name);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory if (S_ISDIR (FileStatus.st_mode)) // It's a directory
{ {
@ -4693,16 +4698,26 @@ static void Brw_ListDir (unsigned Level,const char *Path,const char *PathInTree)
else else
{ {
/***** Check if this subdirectory has files or folders in it *****/ /***** Check if this subdirectory has files or folders in it *****/
if ((NumFilesInThisSubdir = scandir (PathFileRel,&SubdirFileList,NULL,NULL)) <= 2) if ((NumFilesInSubdir = scandir (PathFileRel,&SubdirFileList,NULL,NULL)) >= 0) // No error
{
if (NumFilesInSubdir <= 2)
ExpandTree = Brw_EXPAND_TREE_NOTHING; ExpandTree = Brw_EXPAND_TREE_NOTHING;
else else
/***** Check if the tree starting at this subdirectory must be expanded *****/ /***** Check if the tree starting at this subdirectory must be expanded *****/
ExpandTree = Brw_GetIfExpandedTree (Gbl.FileBrowser.Priv.FullPathInTree) ? Brw_EXPAND_TREE_MINUS : ExpandTree = Brw_GetIfExpandedTree (Gbl.FileBrowser.Priv.FullPathInTree) ? Brw_EXPAND_TREE_MINUS :
Brw_EXPAND_TREE_PLUS; Brw_EXPAND_TREE_PLUS;
for (NumFileInSubdir = 0;
NumFileInSubdir < NumFilesInSubdir;
NumFileInSubdir++)
free ((void *) SubdirFileList[NumFileInSubdir]);
free ((void *) SubdirFileList);
}
else
Lay_ShowErrorAndExit ("Error while scanning directory.");
} }
/***** Write a row for the subdirectory *****/ /***** Write a row for the subdirectory *****/
if (Brw_WriteRowFileBrowser (Level,Brw_IS_FOLDER,ExpandTree,PathInTree,DirFileList[NumFileInThisDir]->d_name)) if (Brw_WriteRowFileBrowser (Level,Brw_IS_FOLDER,ExpandTree,PathInTree,FileList[NumFile]->d_name))
if (ExpandTree == Brw_EXPAND_TREE_MINUS || if (ExpandTree == Brw_EXPAND_TREE_MINUS ||
ExpandTree == Brw_EXPAND_TREE_NOTHING) ExpandTree == Brw_EXPAND_TREE_NOTHING)
if (Level < Brw_MAX_DIR_LEVELS) if (Level < Brw_MAX_DIR_LEVELS)
@ -4711,10 +4726,16 @@ static void Brw_ListDir (unsigned Level,const char *Path,const char *PathInTree)
} }
else if (S_ISREG (FileStatus.st_mode)) // It's a regular file else if (S_ISREG (FileStatus.st_mode)) // It's a regular file
Brw_WriteRowFileBrowser (Level, Brw_WriteRowFileBrowser (Level,
Str_FileIs (DirFileList[NumFileInThisDir]->d_name,"url") ? Brw_IS_LINK : Str_FileIs (FileList[NumFile]->d_name,"url") ? Brw_IS_LINK :
Brw_IS_FILE, Brw_IS_FILE,
Brw_EXPAND_TREE_NOTHING,PathInTree,DirFileList[NumFileInThisDir]->d_name); Brw_EXPAND_TREE_NOTHING,PathInTree,FileList[NumFile]->d_name);
} }
free ((void *) FileList[NumFile]);
}
free ((void *) FileList);
}
else
Lay_ShowErrorAndExit ("Error while scanning directory.");
} }
/*****************************************************************************/ /*****************************************************************************/
@ -6184,18 +6205,25 @@ void Brw_RemoveTree (const char *Path)
{ {
/***** Remove each directory and file under this directory *****/ /***** Remove each directory and file under this directory *****/
/* Scan the directory */ /* Scan the directory */
NumFiles = scandir (Path,&FileList,NULL,NULL); if ((NumFiles = scandir (Path,&FileList,NULL,NULL)) >= 0)
{
/* Remove recursively all the directories and files */ /* Remove recursively all the directories and files */
for (NumFile = 0; for (NumFile = 0;
NumFile < NumFiles; NumFile < NumFiles;
NumFile++) NumFile++)
{
if (strcmp (FileList[NumFile]->d_name,".") && if (strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".." strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{ {
sprintf (PathFileRel,"%s/%s",Path,FileList[NumFile]->d_name); sprintf (PathFileRel,"%s/%s",Path,FileList[NumFile]->d_name);
Brw_RemoveTree (PathFileRel); Brw_RemoveTree (PathFileRel);
} }
free ((void *) FileList[NumFile]);
}
free ((void *) FileList);
}
else
Lay_ShowErrorAndExit ("Error while scanning directory.");
/***** Remove of new the directory, now empty *****/ /***** Remove of new the directory, now empty *****/
if (rmdir (Path)) if (rmdir (Path))
@ -7462,10 +7490,11 @@ static bool Brw_PasteTreeIntoFolder (const char *PathOrg,const char *PathDstInTr
struct dirent **FileList; struct dirent **FileList;
bool AdminMarks; bool AdminMarks;
struct MarksProperties Marks; struct MarksProperties Marks;
int NumFileInThisDir; int NumFile;
int NumFilesInThisDir; int NumFiles;
unsigned NumLevls; unsigned NumLevls;
long FilCod; // File code of the file pasted long FilCod; // File code of the file pasted
bool CopyIsGoingSuccessful = true;
/***** Get the name (only the name) of the origin file or folder *****/ /***** Get the name (only the name) of the origin file or folder *****/
Str_SplitFullPathIntoPathAndFileName (PathOrg, Str_SplitFullPathIntoPathAndFileName (PathOrg,
@ -7516,9 +7545,10 @@ static bool Brw_PasteTreeIntoFolder (const char *PathOrg,const char *PathDstInTr
Lay_ShowErrorAndExit ("Can not paste unknown file type."); Lay_ShowErrorAndExit ("Can not paste unknown file type.");
} }
Lay_ShowAlert (Lay_WARNING,Gbl.Message); Lay_ShowAlert (Lay_WARNING,Gbl.Message);
return false; CopyIsGoingSuccessful = false;
} }
else // Quota not exceeded
{
/***** Copy file or folder *****/ /***** Copy file or folder *****/
if (FileType == Brw_IS_FILE || if (FileType == Brw_IS_FILE ||
FileType == Brw_IS_LINK) // It's a regular file FileType == Brw_IS_LINK) // It's a regular file
@ -7531,9 +7561,10 @@ static bool Brw_PasteTreeIntoFolder (const char *PathOrg,const char *PathDstInTr
Txt_The_copy_has_stopped_when_trying_to_paste_the_link_X_because_there_is_already_an_object_with_that_name, Txt_The_copy_has_stopped_when_trying_to_paste_the_link_X_because_there_is_already_an_object_with_that_name,
FileNameToShow); FileNameToShow);
Lay_ShowAlert (Lay_WARNING,Gbl.Message); Lay_ShowAlert (Lay_WARNING,Gbl.Message);
return false; CopyIsGoingSuccessful = false;
} }
else // Destination file does not exist
{
/***** If the target file browser is that of marks, only HTML files are allowed *****/ /***** If the target file browser is that of marks, only HTML files are allowed *****/
AdminMarks = Gbl.FileBrowser.Type == Brw_ADMI_MARKS_CRS || AdminMarks = Gbl.FileBrowser.Type == Brw_ADMI_MARKS_CRS ||
Gbl.FileBrowser.Type == Brw_ADMI_MARKS_GRP; Gbl.FileBrowser.Type == Brw_ADMI_MARKS_GRP;
@ -7547,10 +7578,12 @@ static bool Brw_PasteTreeIntoFolder (const char *PathOrg,const char *PathDstInTr
sprintf (Gbl.Message,Txt_The_copy_has_stopped_when_trying_to_paste_the_file_X_because_you_can_not_paste_a_file_here_of_a_type_other_than_HTML, sprintf (Gbl.Message,Txt_The_copy_has_stopped_when_trying_to_paste_the_file_X_because_you_can_not_paste_a_file_here_of_a_type_other_than_HTML,
FileNameToShow); FileNameToShow);
Lay_ShowAlert (Lay_WARNING,Gbl.Message); Lay_ShowAlert (Lay_WARNING,Gbl.Message);
return false; CopyIsGoingSuccessful = false;
} }
} }
if (CopyIsGoingSuccessful)
{
/***** Update and check the quota before copying the file *****/ /***** Update and check the quota before copying the file *****/
Gbl.FileBrowser.Size.NumFiles++; Gbl.FileBrowser.Size.NumFiles++;
Gbl.FileBrowser.Size.TotalSiz += (unsigned long long) FileStatus.st_size; Gbl.FileBrowser.Size.TotalSiz += (unsigned long long) FileStatus.st_size;
@ -7560,9 +7593,10 @@ static bool Brw_PasteTreeIntoFolder (const char *PathOrg,const char *PathDstInTr
Txt_The_copy_has_stopped_when_trying_to_paste_the_link_X_because_it_would_exceed_the_disk_quota, Txt_The_copy_has_stopped_when_trying_to_paste_the_link_X_because_it_would_exceed_the_disk_quota,
FileNameToShow); FileNameToShow);
Lay_ShowAlert (Lay_WARNING,Gbl.Message); Lay_ShowAlert (Lay_WARNING,Gbl.Message);
return false; CopyIsGoingSuccessful = false;
} }
else // Quota not exceeded
{
/***** Quota will not be exceeded ==> copy the origin file to the destination file *****/ /***** Quota will not be exceeded ==> copy the origin file to the destination file *****/
Fil_FastCopyOfFiles (PathOrg,PathDstWithFile); Fil_FastCopyOfFiles (PathOrg,PathDstWithFile);
@ -7581,11 +7615,14 @@ static bool Brw_PasteTreeIntoFolder (const char *PathOrg,const char *PathDstInTr
else // FileType == Brw_IS_LINK else // FileType == Brw_IS_LINK
(*NumLinksPasted)++; (*NumLinksPasted)++;
} }
}
}
}
else if (FileType == Brw_IS_FOLDER) // It's a directory else if (FileType == Brw_IS_FOLDER) // It's a directory
{ {
/***** Scan the source directory *****/ /***** Scan the source directory *****/
NumFilesInThisDir = scandir (PathOrg,&FileList,NULL,alphasort); if ((NumFiles = scandir (PathOrg,&FileList,NULL,alphasort)) >= 0) // No error
{
/***** Create the folder in the destination *****/ /***** Create the folder in the destination *****/
if (!Fil_CheckIfPathExists (PathDstWithFile)) // If already exists, don't overwrite if (!Fil_CheckIfPathExists (PathDstWithFile)) // If already exists, don't overwrite
{ {
@ -7598,9 +7635,11 @@ static bool Brw_PasteTreeIntoFolder (const char *PathOrg,const char *PathDstInTr
sprintf (Gbl.Message,Txt_The_copy_has_stopped_when_trying_to_paste_the_folder_X_because_it_would_exceed_the_disk_quota, sprintf (Gbl.Message,Txt_The_copy_has_stopped_when_trying_to_paste_the_folder_X_because_it_would_exceed_the_disk_quota,
FileNameToShow); FileNameToShow);
Lay_ShowAlert (Lay_WARNING,Gbl.Message); Lay_ShowAlert (Lay_WARNING,Gbl.Message);
return false; CopyIsGoingSuccessful = false;
} }
/* The quota will not be exceded ==> create the directory */ else // Quota not exceded
{
/* Create directory */
if (mkdir (PathDstWithFile,(mode_t) 0xFFF) != 0) if (mkdir (PathDstWithFile,(mode_t) 0xFFF) != 0)
Lay_ShowErrorAndExit ("Can not create folder."); Lay_ShowErrorAndExit ("Can not create folder.");
@ -7608,24 +7647,36 @@ static bool Brw_PasteTreeIntoFolder (const char *PathOrg,const char *PathDstInTr
Brw_AddPathToDB (Gbl.Usrs.Me.UsrDat.UsrCod,FileType, Brw_AddPathToDB (Gbl.Usrs.Me.UsrDat.UsrCod,FileType,
PathDstInTreeWithFile,false,Brw_LICENSE_DEFAULT); PathDstInTreeWithFile,false,Brw_LICENSE_DEFAULT);
} }
}
/***** Copy each of the files and folders from the origin to the destination *****/ /***** Copy each of the files and folders from the origin to the destination *****/
for (NumFileInThisDir = 0; for (NumFile = 0;
NumFileInThisDir < NumFilesInThisDir; NumFile < NumFiles;
NumFileInThisDir++) NumFile++)
if (strcmp (FileList[NumFileInThisDir]->d_name,".") &&
strcmp (FileList[NumFileInThisDir]->d_name,"..")) // Skip directories "." and ".."
{ {
sprintf (PathInFolderOrg,"%s/%s",PathOrg,FileList[NumFileInThisDir]->d_name); if (CopyIsGoingSuccessful &&
strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{
sprintf (PathInFolderOrg,"%s/%s",PathOrg,FileList[NumFile]->d_name);
if (!Brw_PasteTreeIntoFolder (PathInFolderOrg,PathDstInTreeWithFile, if (!Brw_PasteTreeIntoFolder (PathInFolderOrg,PathDstInTreeWithFile,
NumFilesPasted,NumFoldsPasted,NumLinksPasted, NumFilesPasted,NumFoldsPasted,NumLinksPasted,
FirstFilCod)) FirstFilCod))
return false; CopyIsGoingSuccessful = false;
} }
free ((void *) FileList[NumFile]);
}
free ((void *) FileList);
}
else
Lay_ShowErrorAndExit ("Error while scanning directory.");
if (CopyIsGoingSuccessful)
(*NumFoldsPasted)++; (*NumFoldsPasted)++;
} }
return true; }
return CopyIsGoingSuccessful;
} }
/*****************************************************************************/ /*****************************************************************************/
@ -11310,8 +11361,8 @@ void Brw_RemoveOldFiles (void)
static void Brw_RemoveOldFilesInBrowser (time_t TimeRemoveFilesOlder) static void Brw_RemoveOldFilesInBrowser (time_t TimeRemoveFilesOlder)
{ {
extern const char *Txt_Folders_removed;
extern const char *Txt_Files_removed; extern const char *Txt_Files_removed;
extern const char *Txt_Folders_removed;
/***** Remove old files recursively *****/ /***** Remove old files recursively *****/
Gbl.FileBrowser.Removed.NumFiles = Gbl.FileBrowser.Removed.NumFiles =
@ -11319,9 +11370,10 @@ static void Brw_RemoveOldFilesInBrowser (time_t TimeRemoveFilesOlder)
Brw_ScanDirRemovingOlfFiles (1,Gbl.FileBrowser.Priv.PathRootFolder,TimeRemoveFilesOlder); Brw_ScanDirRemovingOlfFiles (1,Gbl.FileBrowser.Priv.PathRootFolder,TimeRemoveFilesOlder);
/***** Success message *****/ /***** Success message *****/
sprintf (Gbl.Message,"%s: %u. %s: %u.", sprintf (Gbl.Message,"%s: %u.<br />"
Txt_Folders_removed,Gbl.FileBrowser.Removed.NumFolders, "%s: %u.",
Txt_Files_removed ,Gbl.FileBrowser.Removed.NumFiles); Txt_Files_removed ,Gbl.FileBrowser.Removed.NumFiles,
Txt_Folders_removed,Gbl.FileBrowser.Removed.NumFolders);
Lay_ShowAlert (Lay_SUCCESS,Gbl.Message); Lay_ShowAlert (Lay_SUCCESS,Gbl.Message);
} }
@ -11333,26 +11385,26 @@ static void Brw_ScanDirRemovingOlfFiles (unsigned Level,const char *Path,
time_t TimeRemoveFilesOlder) time_t TimeRemoveFilesOlder)
{ {
struct dirent **FileList; struct dirent **FileList;
int NumFileInThisDir; int NumFile;
int NumFilesInThisDir; int NumFiles;
char PathFileRel[PATH_MAX+1]; char PathFileRel[PATH_MAX+1];
struct stat FileStatus; struct stat FileStatus;
/***** Scan directory *****/ /***** Scan directory *****/
NumFilesInThisDir = scandir (Path,&FileList,NULL,alphasort); if ((NumFiles = scandir (Path,&FileList,NULL,alphasort)) >= 0) // No error
{
if (NumFilesInThisDir > 2) if (NumFiles > 2)
{ {
/***** Check file by file removing old files *****/ /***** Check file by file removing old files *****/
for (NumFileInThisDir = 0; for (NumFile = 0;
NumFileInThisDir < NumFilesInThisDir; NumFile < NumFiles;
NumFileInThisDir++) NumFile++)
{ {
if (strcmp (FileList[NumFileInThisDir]->d_name,".") && if (strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFileInThisDir]->d_name,"..")) // Skip directories "." and ".." strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{ {
/***** Construct the full path of the file or folder *****/ /***** Construct the full path of the file or folder *****/
sprintf (PathFileRel,"%s/%s",Path,FileList[NumFileInThisDir]->d_name); sprintf (PathFileRel,"%s/%s",Path,FileList[NumFile]->d_name);
/***** Get file or folder status *****/ /***** Get file or folder status *****/
lstat (PathFileRel,&FileStatus); lstat (PathFileRel,&FileStatus);
@ -11368,27 +11420,27 @@ static void Brw_ScanDirRemovingOlfFiles (unsigned Level,const char *Path,
Gbl.FileBrowser.Removed.NumFiles++; Gbl.FileBrowser.Removed.NumFiles++;
} }
} }
free (FileList[NumFileInThisDir]); free ((void *) FileList[NumFile]);
} }
free (FileList); free ((void *) FileList);
/***** Rescan folder in order to see /***** Rescan folder in order to see
if it's now empty after deletion *****/ if it's now empty after deletion *****/
if (Level > 1) if (Level > 1)
{ {
/* Count number of files in folder */ /* Count number of files in folder */
NumFilesInThisDir = scandir (Path,&FileList,NULL,alphasort); NumFiles = scandir (Path,&FileList,NULL,alphasort);
/* Free list of files */ /* Free list of files */
for (NumFileInThisDir = 0; for (NumFile = 0;
NumFileInThisDir < NumFilesInThisDir; NumFile < NumFiles;
NumFileInThisDir++) NumFile++)
free (FileList[NumFileInThisDir]); free ((void *) FileList[NumFile]);
free (FileList); free ((void *) FileList);
} }
} }
if (Level > 1 && NumFilesInThisDir <= 2) // It's an empty folder inside root folder if (Level > 1 && NumFiles <= 2) // It's an empty folder inside root folder
{ {
/***** Get folder status *****/ /***** Get folder status *****/
lstat (Path,&FileStatus); lstat (Path,&FileStatus);
@ -11401,3 +11453,6 @@ static void Brw_ScanDirRemovingOlfFiles (unsigned Level,const char *Path,
} }
} }
} }
else
Lay_ShowErrorAndExit ("Error while scanning directory.");
}

View File

@ -4034,35 +4034,36 @@ int swad__getDirectoryTree (struct soap *soap,
static void Svc_ListDir (unsigned Level,const char *Path,const char *PathInTree) static void Svc_ListDir (unsigned Level,const char *Path,const char *PathInTree)
{ {
extern const char *Txt_NEW_LINE; extern const char *Txt_NEW_LINE;
struct dirent **DirFileList; struct dirent **FileList;
int NumFileInThisDir; int NumFile;
int NumFilesInThisDir; int NumFiles;
char PathFileRel[PATH_MAX+1]; char PathFileRel[PATH_MAX+1];
char PathFileInExplTree[PATH_MAX+1]; char PathFileInExplTree[PATH_MAX+1];
struct stat FileStatus; struct stat FileStatus;
/***** Scan directory *****/ /***** Scan directory *****/
NumFilesInThisDir = scandir (Path,&DirFileList,NULL,alphasort); if ((NumFiles = scandir (Path,&FileList,NULL,alphasort)) >= 0) // No error
/***** List files *****/
for (NumFileInThisDir = 0;
NumFileInThisDir < NumFilesInThisDir;
NumFileInThisDir++)
if (strcmp (DirFileList[NumFileInThisDir]->d_name,".") &&
strcmp (DirFileList[NumFileInThisDir]->d_name,"..")) // Skip directories "." and ".."
{ {
sprintf (PathFileRel ,"%s/%s",Path ,DirFileList[NumFileInThisDir]->d_name); /***** List files *****/
sprintf (PathFileInExplTree,"%s/%s",PathInTree,DirFileList[NumFileInThisDir]->d_name); for (NumFile = 0;
NumFile < NumFiles;
NumFile++)
{
if (strcmp (FileList[NumFile]->d_name,".") &&
strcmp (FileList[NumFile]->d_name,"..")) // Skip directories "." and ".."
{
sprintf (PathFileRel ,"%s/%s",Path ,FileList[NumFile]->d_name);
sprintf (PathFileInExplTree,"%s/%s",PathInTree,FileList[NumFile]->d_name);
lstat (PathFileRel,&FileStatus); lstat (PathFileRel,&FileStatus);
/***** Construct the full path of the file or folder *****/ /***** Construct the full path of the file or folder *****/
Brw_SetFullPathInTree (PathInTree,DirFileList[NumFileInThisDir]->d_name); Brw_SetFullPathInTree (PathInTree,FileList[NumFile]->d_name);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory if (S_ISDIR (FileStatus.st_mode)) // It's a directory
{ {
/***** Write a row for the subdirectory *****/ /***** Write a row for the subdirectory *****/
if (Svc_WriteRowFileBrowser (Level,Brw_IS_FOLDER,DirFileList[NumFileInThisDir]->d_name)) if (Svc_WriteRowFileBrowser (Level,Brw_IS_FOLDER,FileList[NumFile]->d_name))
{ {
/* List subtree starting at this this directory */ /* List subtree starting at this this directory */
Svc_ListDir (Level + 1,PathFileRel,PathFileInExplTree); Svc_ListDir (Level + 1,PathFileRel,PathFileInExplTree);
@ -4074,9 +4075,14 @@ static void Svc_ListDir (unsigned Level,const char *Path,const char *PathInTree)
} }
else if (S_ISREG (FileStatus.st_mode)) // It's a regular file else if (S_ISREG (FileStatus.st_mode)) // It's a regular file
Svc_WriteRowFileBrowser (Level, Svc_WriteRowFileBrowser (Level,
Str_FileIs (DirFileList[NumFileInThisDir]->d_name,"url") ? Brw_IS_LINK : Str_FileIs (FileList[NumFile]->d_name,"url") ? Brw_IS_LINK :
Brw_IS_FILE, Brw_IS_FILE,
DirFileList[NumFileInThisDir]->d_name); FileList[NumFile]->d_name);
}
free ((void *) FileList[NumFile]);
}
free ((void *) FileList);
} }
} }