Version 16.111.9

This commit is contained in:
Antonio Cañas Vargas 2016-12-29 22:00:35 +01:00
parent efd20a9e58
commit 9d4de6d57a
5 changed files with 83 additions and 68 deletions

View File

@ -189,13 +189,14 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 16.111.8 (2016-12-28)"
#define Log_PLATFORM_VERSION "SWAD 16.111.9 (2016-12-29)"
#define CSS_FILE "swad16.111.5.css"
#define JS_FILE "swad16.101.js"
// 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 16.111.9: Dec 29, 2016 Fixed bugs in lstat, reported by Coverity. (211138 lines)
Version 16.111.8: Dec 28, 2016 Fixed bug in notifications, reported by Coverity. (211119 lines)
Version 16.111.7: Dec 28, 2016 Fixed minor bug in groups, reported by Coverity. (211114 lines)
Version 16.111.6: Dec 28, 2016 Fixed bug in assigments, reported by Coverity. (211109 lines)

View File

@ -440,8 +440,9 @@ void Fil_RemoveTree (const char *Path)
if (Fil_CheckIfPathExists (Path))
{
lstat (Path,&FileStatus);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory
if (lstat (Path,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
else if (S_ISDIR (FileStatus.st_mode)) // It's a directory
{
if (rmdir (Path))
{
@ -501,8 +502,9 @@ void Fil_RemoveOldTmpFiles (const char *Path,time_t TimeToRemove,bool RemoveDire
char Path2[PATH_MAX+1];
struct stat FileStatus;
lstat (Path,&FileStatus);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory
if (lstat (Path,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
else if (S_ISDIR (FileStatus.st_mode)) // It's a directory
{
/***** Scan the directory *****/
if ((NumFiles = scandir (Path,&FileList,NULL,NULL)) >= 0) // No error

View File

@ -4983,8 +4983,9 @@ static void Brw_CalcSizeOfDirRecursive (unsigned Level,char *Path)
/* Update counters depending on whether it's a directory or a regular file */
sprintf (PathFileRel,"%s/%s",Path,FileList[NumFile]->d_name);
lstat (PathFileRel,&FileStatus);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory
if (lstat (PathFileRel,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
else if (S_ISDIR (FileStatus.st_mode)) // It's a directory
{
Gbl.FileBrowser.Size.NumFolds++;
Gbl.FileBrowser.Size.TotalSiz += (unsigned long long) FileStatus.st_size;
@ -5038,8 +5039,9 @@ static void Brw_ListDir (unsigned Level,const char *Path,const char *PathInTree)
Brw_SetFullPathInTree (PathInTree,FileList[NumFile]->d_name);
/***** Get file or folder status *****/
lstat (PathFileRel,&FileStatus);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory
if (lstat (PathFileRel,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
else if (S_ISDIR (FileStatus.st_mode)) // It's a directory
{
if (Gbl.FileBrowser.FullTree)
ExpandTree = Brw_EXPAND_TREE_NOTHING;
@ -6206,8 +6208,9 @@ void Brw_RemFileFromTree (void)
sprintf (Path,"%s/%s",Gbl.FileBrowser.Priv.PathAboveRootFolder,Gbl.FileBrowser.Priv.FullPathInTree);
/***** Check if is a file/link or a folder *****/
lstat (Path,&FileStatus);
if (S_ISREG (FileStatus.st_mode)) // It's a file or a link
if (lstat (Path,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
else if (S_ISREG (FileStatus.st_mode)) // It's a file or a link
{
/* Name of the file/link to be shown */
Brw_LimitLengthFileNameToShow (Str_FileIs (Gbl.FileBrowser.FilFolLnkName,"url") ? Brw_IS_LINK :
@ -6256,8 +6259,9 @@ void Brw_RemFolderFromTree (void)
sprintf (Path,"%s/%s",Gbl.FileBrowser.Priv.PathAboveRootFolder,Gbl.FileBrowser.Priv.FullPathInTree);
/***** Check if it's a file or a folder *****/
lstat (Path,&FileStatus);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory
if (lstat (Path,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
else if (S_ISDIR (FileStatus.st_mode)) // It's a directory
if (Brw_RemoveFolderFromDiskAndDB (Path,
Gbl.FileBrowser.Priv.FullPathInTree))
{
@ -7631,14 +7635,14 @@ static bool Brw_PasteTreeIntoFolder (unsigned LevelOrg,
FileNameOrg);
/***** Is it a file or a folder? *****/
lstat (PathOrg,&FileStatus);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory
FileType = Brw_IS_UNKNOWN;
if (lstat (PathOrg,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
else 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 (FileNameOrg,"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;
/***** Name of the file/folder/link to be shown ****/
Brw_LimitLengthFileNameToShow (FileType,FileNameOrg,FileNameToShow);
@ -10166,7 +10170,7 @@ bool Brw_GetFileTypeSizeAndDate (struct FileMetadata *FileMetadata)
sprintf (Path,"%s/%s",Gbl.FileBrowser.Priv.PathAboveRootFolder,
FileMetadata->FullPathInTree);
if (lstat (Path,&FileStatus))
if (lstat (Path,&FileStatus)) // On success ==> 0 is returned
{
// Error on lstat
FileMetadata->FileType = Brw_IS_UNKNOWN;
@ -11681,10 +11685,10 @@ static void Brw_ScanDirRemovingOldFiles (unsigned Level,const char *Path,
/***** Save folder status *****/
// Folder st_mtime must be saved before remove files inside it
// because st_mtime is updated by the deletion
lstat (Path,&FolderStatus);
if (lstat (Path,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
/***** Scan directory *****/
if ((NumFiles = scandir (Path,&FileList,NULL,alphasort)) >= 0) // No error
else if ((NumFiles = scandir (Path,&FileList,NULL,alphasort)) >= 0) // No error
{
/***** Check file by file removing old files *****/
for (NumFile = 0;
@ -11699,8 +11703,9 @@ static void Brw_ScanDirRemovingOldFiles (unsigned Level,const char *Path,
sprintf (PathFileInExplTree,"%s/%s",PathInTree,FileList[NumFile]->d_name);
/***** Get file or folder status *****/
lstat (PathFileRel,&FileStatus);
if (S_ISDIR (FileStatus.st_mode)) // It's a folder
if (lstat (PathFileRel,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
else if (S_ISDIR (FileStatus.st_mode)) // It's a folder
/* Scan subtree starting at this this directory recursively */
Brw_ScanDirRemovingOldFiles (Level + 1,PathFileRel,
PathFileInExplTree,

View File

@ -4386,29 +4386,30 @@ static void Svc_ListDir (unsigned Level,const char *Path,const char *PathInTree)
sprintf (PathFileRel ,"%s/%s",Path ,FileList[NumFile]->d_name);
sprintf (PathFileInExplTree,"%s/%s",PathInTree,FileList[NumFile]->d_name);
lstat (PathFileRel,&FileStatus);
/***** Construct the full path of the file or folder *****/
Brw_SetFullPathInTree (PathInTree,FileList[NumFile]->d_name);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory
if (!lstat (PathFileRel,&FileStatus)) // On success ==> 0 is returned
{
/***** Write a row for the subdirectory *****/
if (Svc_WriteRowFileBrowser (Level,Brw_IS_FOLDER,FileList[NumFile]->d_name))
{
/* List subtree starting at this this directory */
Svc_ListDir (Level + 1,PathFileRel,PathFileInExplTree);
/***** Construct the full path of the file or folder *****/
Brw_SetFullPathInTree (PathInTree,FileList[NumFile]->d_name);
/* Indent and end dir */
Svc_IndentXMLLine (Level);
fprintf (Gbl.F.XML,"</dir>%s",Txt_NEW_LINE);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory
{
/***** Write a row for the subdirectory *****/
if (Svc_WriteRowFileBrowser (Level,Brw_IS_FOLDER,FileList[NumFile]->d_name))
{
/* List subtree starting at this this directory */
Svc_ListDir (Level + 1,PathFileRel,PathFileInExplTree);
/* Indent and end dir */
Svc_IndentXMLLine (Level);
fprintf (Gbl.F.XML,"</dir>%s",Txt_NEW_LINE);
}
}
else if (S_ISREG (FileStatus.st_mode)) // It's a regular file
Svc_WriteRowFileBrowser (Level,
Str_FileIs (FileList[NumFile]->d_name,"url") ? Brw_IS_LINK :
Brw_IS_FILE,
FileList[NumFile]->d_name);
}
else if (S_ISREG (FileStatus.st_mode)) // It's a regular file
Svc_WriteRowFileBrowser (Level,
Str_FileIs (FileList[NumFile]->d_name,"url") ? Brw_IS_LINK :
Brw_IS_FILE,
FileList[NumFile]->d_name);
}
free ((void *) FileList[NumFile]);

View File

@ -229,18 +229,21 @@ void ZIP_CreateZIPAsgWrk (void)
if (Result == 0)
{
/***** Get file size *****/
lstat (PathFileZIP,&FileStatus);
if (lstat (PathFileZIP,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
else
{
/***** Create URL pointing to ZIP file *****/
sprintf (URLWithSpaces,"%s/%s/%s/%s",
Cfg_URL_SWAD_PUBLIC,
Cfg_FOLDER_FILE_BROWSER_TMP,
Gbl.FileBrowser.TmpPubDir,
FileNameZIP);
Str_CopyStrChangingSpaces (URLWithSpaces,URL,PATH_MAX); // In HTML, URL must have no spaces
/***** Create URL pointing to ZIP file *****/
sprintf (URLWithSpaces,"%s/%s/%s/%s",
Cfg_URL_SWAD_PUBLIC,
Cfg_FOLDER_FILE_BROWSER_TMP,
Gbl.FileBrowser.TmpPubDir,
FileNameZIP);
Str_CopyStrChangingSpaces (URLWithSpaces,URL,PATH_MAX); // In HTML, URL must have no spaces
/****** Link to download file *****/
ZIP_ShowLinkToDownloadZIP (FileNameZIP,URL,FileStatus.st_size,0);
/****** Link to download file *****/
ZIP_ShowLinkToDownloadZIP (FileNameZIP,URL,FileStatus.st_size,0);
}
}
else
Lay_ShowErrorAndExit ("Can not compress files into zip file.");
@ -456,18 +459,21 @@ static void ZIP_CompressFolderIntoZIP (void)
if (Result == 0)
{
/***** Get file size *****/
lstat (PathFileZIP,&FileStatus);
if (lstat (PathFileZIP,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
else
{
/***** Create URL pointing to ZIP file *****/
sprintf (URLWithSpaces,"%s/%s/%s/%s",
Cfg_URL_SWAD_PUBLIC,
Cfg_FOLDER_FILE_BROWSER_TMP,
Gbl.FileBrowser.TmpPubDir,
FileNameZIP);
Str_CopyStrChangingSpaces (URLWithSpaces,URL,PATH_MAX); // In HTML, URL must have no spaces
/***** Create URL pointing to ZIP file *****/
sprintf (URLWithSpaces,"%s/%s/%s/%s",
Cfg_URL_SWAD_PUBLIC,
Cfg_FOLDER_FILE_BROWSER_TMP,
Gbl.FileBrowser.TmpPubDir,
FileNameZIP);
Str_CopyStrChangingSpaces (URLWithSpaces,URL,PATH_MAX); // In HTML, URL must have no spaces
/****** Link to download file *****/
ZIP_ShowLinkToDownloadZIP (FileNameZIP,URL,FileStatus.st_size,UncompressedSize);
/****** Link to download file *****/
ZIP_ShowLinkToDownloadZIP (FileNameZIP,URL,FileStatus.st_size,UncompressedSize);
}
}
else
Lay_ShowErrorAndExit ("Can not compress files into zip file.");
@ -533,14 +539,14 @@ static unsigned long long ZIP_CloneDir (const char *Path,const char *PathClone,c
sprintf (PathFileClone,"%s/%s",
PathClone,FileList[NumFile]->d_name);
lstat (PathFile,&FileStatus);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory
FileType = Brw_IS_UNKNOWN;
if (lstat (PathFile,&FileStatus)) // On success ==> 0 is returned
Lay_ShowErrorAndExit ("Can not get information about a file or folder.");
else 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;
Hidden = (SeeDocsZone || SeeMarks) ? Brw_CheckIfFileOrFolderIsSetAsHiddenInDB (FileType,PathFileInTree) :
false;