Version 16.15.5

This commit is contained in:
Antonio Cañas Vargas 2016-10-06 22:18:33 +02:00
parent 1192325851
commit a356c01ca7
15 changed files with 163 additions and 89 deletions

View File

@ -40,6 +40,7 @@
#include "swad_parameter.h"
#include "swad_preference.h"
#include "swad_profile.h"
#include "swad_report.h"
#include "swad_social.h"
/*****************************************************************************/
@ -994,6 +995,9 @@ void Acc_CompletelyEliminateAccount (struct UsrData *UsrDat,
/***** Remove user from table of seen announcements *****/
Ann_RemoveUsrFromSeenAnnouncements (UsrDat->UsrCod);
/***** Remove user's usage reports *****/
Rep_RemoveUsrUsageReports (UsrDat->UsrCod);
/***** Remove user from table of connected users *****/
sprintf (Query,"DELETE FROM connected WHERE UsrCod='%ld'",
UsrDat->UsrCod);
@ -1045,7 +1049,7 @@ static void Acc_RemoveUsrBriefcase (struct UsrData *UsrDat)
/***** Remove files of the user's briefcase from disc *****/
Usr_ConstructPathUsr (UsrDat->UsrCod,PathRelUsr);
Brw_RemoveTree (PathRelUsr);
Fil_RemoveTree (PathRelUsr);
}
/*****************************************************************************/

View File

@ -1609,7 +1609,7 @@ void Ctr_RemoveCentre (void)
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_CTR,
(unsigned) (Ctr.CtrCod % 100),
(unsigned) Ctr.CtrCod);
Brw_RemoveTree (PathCtr);
Fil_RemoveTree (PathCtr);
/***** Remove centre *****/
sprintf (Query,"DELETE FROM centres WHERE CtrCod='%ld'",

View File

@ -146,13 +146,15 @@
/****************************** Public constants *****************************/
/*****************************************************************************/
#define Log_PLATFORM_VERSION "SWAD 16.15.3 (2016-10-06)"
#define Log_PLATFORM_VERSION "SWAD 16.15.5 (2016-10-06)"
#define CSS_FILE "swad15.229.css"
#define JS_FILE "swad15.238.1.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.15.5: Oct 06, 2016 Fix bug removing user's usage reports. (206023 lines)
Version 16.15.4: Oct 06, 2016 When a user is removed, all his/her user's usage reports are removed. (206022 lines)
Version 16.15.3: Oct 06, 2016 Do not write date when requesting a user's usage report. (205965 lines)
Version 16.15.2: Oct 06, 2016 Code refactoring in user's usage report. (205966 lines)
1 change necessary in database:

View File

@ -2303,10 +2303,10 @@ static void Crs_EmptyCourseCompletely (long CrsCod)
/***** Remove directories of the course *****/
sprintf (PathRelCrs,"%s/%s/%ld",
Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_CRS,CrsCod);
Brw_RemoveTree (PathRelCrs);
Fil_RemoveTree (PathRelCrs);
sprintf (PathRelCrs,"%s/%s/%ld",
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_CRS,CrsCod);
Brw_RemoveTree (PathRelCrs);
Fil_RemoveTree (PathRelCrs);
}
/*****************************************************************************/

View File

@ -2387,7 +2387,7 @@ void Deg_RemoveDegreeCompletely (long DegCod)
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_DEG,
(unsigned) (DegCod % 100),
(unsigned) DegCod);
Brw_RemoveTree (PathDeg);
Fil_RemoveTree (PathDeg);
/***** Remove administrators of this degree *****/
sprintf (Query,"DELETE FROM admin WHERE Scope='Deg' AND Cod='%ld'",

View File

@ -425,6 +425,70 @@ void Fil_CreateDirIfNotExists (const char *Path)
}
}
/*****************************************************************************/
/************************ Remove a directory recursively *********************/
/*****************************************************************************/
// If the tree of directories and files exists, remove it
void Fil_RemoveTree (const char *Path)
{
struct stat FileStatus;
struct dirent **FileList;
int NumFile,NumFiles;
char PathFileRel[PATH_MAX+1];
bool Error;
if (Fil_CheckIfPathExists (Path))
{
lstat (Path,&FileStatus);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory
{
if (rmdir (Path))
{
Error = false;
if (errno == ENOTEMPTY)
{
/***** Remove each directory and file under this directory *****/
/* Scan the directory */
if ((NumFiles = scandir (Path,&FileList,NULL,NULL)) >= 0)
{
/* Remove recursively all the directories and files */
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);
Fil_RemoveTree (PathFileRel);
}
free ((void *) FileList[NumFile]);
}
free ((void *) FileList);
}
else
Lay_ShowErrorAndExit ("Error while scanning directory.");
/***** Remove of new the directory, now empty *****/
if (rmdir (Path))
Error = true;
}
else
Error = true;
if (Error)
{
sprintf (Gbl.Message,"Can not remove folder %s.",Path);
Lay_ShowErrorAndExit (Gbl.Message);
}
}
}
else // It's a file
if (unlink (Path))
Lay_ShowErrorAndExit ("Can not remove file.");
}
}
/*****************************************************************************/
/********************* Remove old temporary directories **********************/
/*****************************************************************************/
@ -573,4 +637,3 @@ void Fil_WriteFileSizeFull (double SizeInBytes,
else
sprintf (FileSizeStr,"%.1f&nbsp;TiB",SizeInBytes / Ti);
}

View File

@ -68,9 +68,12 @@ struct Param *Fil_StartReceptionOfFile (const char *ParamFile,
bool Fil_EndReceptionOfFile (char *FileNameDataTmp,struct Param *Param);
void Fil_CreateUpdateFile (const char *CurrentName,const char *ExtensionOldName,char *OldName,char *NewName,FILE **NewFile);
void Fil_CloseUpdateFile (const char *CurrentName,const char *OldName,const char *NewName,FILE *NewFile);
bool Fil_RenameFileOrDir (const char *PathOld,const char *PathNew);
bool Fil_CheckIfPathExists (const char *Path);
void Fil_CreateDirIfNotExists (const char *Path);
void Fil_RemoveTree (const char *Path);
void Fil_RemoveOldTmpFiles (const char *Path,time_t TimeToRemove,bool RemoveDirectory);
void Fil_FastCopyOfFiles (const char *PathSrc,const char *PathTgt);
void Fil_FastCopyOfOpenFiles (FILE *FileSrc,FILE *FileTgt);

View File

@ -2897,7 +2897,7 @@ void Brw_RemoveFoldersAssignmentsIfExistForAllUsrs (const char *FolderName)
UsrCod, // User's code
Brw_INTERNAL_NAME_ROOT_FOLDER_ASSIGNMENTS,
FolderName);
Brw_RemoveTree (PathFolder);
Fil_RemoveTree (PathFolder);
}
/***** Free structure that stores the query result *****/
@ -6411,7 +6411,7 @@ void Brw_RemSubtreeInFileBrowser (void)
sprintf (Path,"%s/%s",Gbl.FileBrowser.Priv.PathAboveRootFolder,Gbl.FileBrowser.Priv.FullPathInTree);
/***** Remove the whole tree *****/
Brw_RemoveTree (Path);
Fil_RemoveTree (Path);
/* If a folder is removed,
it is necessary to remove it from the database and all the files o folders under that folder */
@ -6434,70 +6434,6 @@ void Brw_RemSubtreeInFileBrowser (void)
Brw_ShowAgainFileBrowserOrWorks ();
}
/*****************************************************************************/
/************************* Remove a folder recursively ***********************/
/*****************************************************************************/
// If the tree of directories and files exists, remove it
void Brw_RemoveTree (const char *Path)
{
struct stat FileStatus;
struct dirent **FileList;
int NumFile,NumFiles;
char PathFileRel[PATH_MAX+1];
bool Error;
if (Fil_CheckIfPathExists (Path))
{
lstat (Path,&FileStatus);
if (S_ISDIR (FileStatus.st_mode)) // It's a directory
{
if (rmdir (Path))
{
Error = false;
if (errno == ENOTEMPTY)
{
/***** Remove each directory and file under this directory *****/
/* Scan the directory */
if ((NumFiles = scandir (Path,&FileList,NULL,NULL)) >= 0)
{
/* Remove recursively all the directories and files */
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);
Brw_RemoveTree (PathFileRel);
}
free ((void *) FileList[NumFile]);
}
free ((void *) FileList);
}
else
Lay_ShowErrorAndExit ("Error while scanning directory.");
/***** Remove of new the directory, now empty *****/
if (rmdir (Path))
Error = true;
}
else
Error = true;
if (Error)
{
sprintf (Gbl.Message,"Can not remove folder %s.",Path);
Lay_ShowErrorAndExit (Gbl.Message);
}
}
}
else // It's a file
if (unlink (Path))
Lay_ShowErrorAndExit ("Can not remove file.");
}
}
/*****************************************************************************/
/********************* Expand a folder in a file browser *********************/
/*****************************************************************************/
@ -8378,7 +8314,7 @@ void Brw_RecFolderFileBrowser (void)
Brw_SetMaxQuota ();
if (Brw_CheckIfQuotaExceded ())
{
Brw_RemoveTree (Path);
Fil_RemoveTree (Path);
sprintf (Gbl.Message,Txt_Can_not_create_the_folder_X_because_it_would_exceed_the_disk_quota,
Gbl.FileBrowser.NewFilFolLnkName);
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
@ -8666,7 +8602,7 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
/* Rename the temporary */
if (rename (PathTmp,Path)) // Fail
{
Brw_RemoveTree (PathTmp);
Fil_RemoveTree (PathTmp);
sprintf (Gbl.Message,Txt_UPLOAD_FILE_could_not_create_file_NO_HTML,
Gbl.FileBrowser.NewFilFolLnkName);
}
@ -8677,7 +8613,7 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
Brw_SetMaxQuota ();
if (Brw_CheckIfQuotaExceded ())
{
Brw_RemoveTree (Path);
Fil_RemoveTree (Path);
sprintf (Gbl.Message,Txt_UPLOAD_FILE_X_quota_exceeded_NO_HTML,
Gbl.FileBrowser.NewFilFolLnkName);
}
@ -8748,7 +8684,7 @@ static bool Brw_RcvFileInFileBrw (Brw_UploadType_t UploadType)
}
}
else // Error in file reception. File probably too big
Brw_RemoveTree (PathTmp);
Fil_RemoveTree (PathTmp);
}
}
}
@ -8858,7 +8794,7 @@ void Brw_RecLinkFileBrowser (void)
Brw_SetMaxQuota ();
if (Brw_CheckIfQuotaExceded ())
{
Brw_RemoveTree (Path);
Fil_RemoveTree (Path);
sprintf (Gbl.Message,Txt_Can_not_create_the_link_X_because_it_would_exceed_the_disk_quota,
FileName);
Lay_ShowAlert (Lay_WARNING,Gbl.Message);
@ -11254,7 +11190,7 @@ void Brw_RemoveGrpZones (long CrsCod,long GrpCod)
/***** Remove group zones *****/
sprintf (PathGrpFileZones,"%s/%s/%ld/grp/%ld",
Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_CRS,CrsCod,GrpCod);
Brw_RemoveTree (PathGrpFileZones);
Fil_RemoveTree (PathGrpFileZones);
}
/*****************************************************************************/
@ -11273,7 +11209,7 @@ void Brw_RemoveUsrWorksInCrs (struct UsrData *UsrDat,struct Course *Crs,Cns_Quie
sprintf (PathUsrInCrs,"%s/%s/%ld/usr/%02u/%ld",
Cfg_PATH_SWAD_PRIVATE,Cfg_FOLDER_CRS,Crs->CrsCod,
(unsigned) (UsrDat->UsrCod % 100),UsrDat->UsrCod);
Brw_RemoveTree (PathUsrInCrs);
Fil_RemoveTree (PathUsrInCrs);
// If this was the last user in his/her subfolder ==> the subfolder will be empty
/***** Write message *****/

View File

@ -217,7 +217,6 @@ long Brw_AddPathToDB (long PublisherUsrCod,Brw_FileType_t FileType,
void Brw_RemoveExpiredExpandedFolders (void);
void Brw_RemoveTree (const char *Path);
void Brw_CalcSizeOfDir (char *Path);
void Brw_SetFullPathInTree (const char *PathInTreeUntilFileOrFolder,const char *FilFolLnkName);

View File

@ -2224,7 +2224,7 @@ void Inf_ReceivePagInfo (void)
if (Str_FileIs (SourceFileName,"html") ||
Str_FileIs (SourceFileName,"htm" )) // .html or .htm file
{
Brw_RemoveTree (PathRelDirHTML);
Fil_RemoveTree (PathRelDirHTML);
Fil_CreateDirIfNotExists (PathRelDirHTML);
sprintf (PathRelFileHTML,"%s/index.html",PathRelDirHTML);
if (Fil_EndReceptionOfFile (PathRelFileHTML,Param))
@ -2237,7 +2237,7 @@ void Inf_ReceivePagInfo (void)
}
else if (Str_FileIs (SourceFileName,"zip")) // .zip file
{
Brw_RemoveTree (PathRelDirHTML);
Fil_RemoveTree (PathRelDirHTML);
Fil_CreateDirIfNotExists (PathRelDirHTML);
sprintf (PathRelFileZIP,"%s/%s.zip",
Gbl.CurrentCrs.PathPriv,

View File

@ -1497,7 +1497,7 @@ void Ins_RemoveInstitution (void)
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_INS,
(unsigned) (Ins.InsCod % 100),
(unsigned) Ins.InsCod);
Brw_RemoveTree (PathIns);
Fil_RemoveTree (PathIns);
/***** Remove institution *****/
sprintf (Query,"DELETE FROM institutions WHERE InsCod='%ld'",

View File

@ -426,5 +426,5 @@ void Log_RemoveLogo (Sco_Scope_t Scope)
(unsigned) (Cod % 100),
(unsigned) Cod,
(unsigned) Cod);
Brw_RemoveTree (FileNameLogo);
Fil_RemoveTree (FileNameLogo);
}

View File

@ -27,7 +27,6 @@
#include <sys/stat.h> // For mkdir
#include <sys/types.h> // For mkdir
#include <unistd.h> // For unlink
#include "swad_database.h"
#include "swad_global.h"
@ -137,6 +136,9 @@ static void Rep_ShowMyHitsPerYear (bool AnyCourse,long CrsCod,Rol_Role_t Role,
static void Rep_DrawBarNumHits (float HitsNum,float HitsMax,
unsigned MaxBarWidth);
static void Rep_RemoveUsrReportsFiles (long UsrCod);
static void Rep_RemoveUsrReportsFromDB (long UsrCod);
/*****************************************************************************/
/******* Request my usage report (report on my use of the platform) **********/
/*****************************************************************************/
@ -428,7 +430,7 @@ static void Rep_CreateNewReportEntryIntoDB (const struct tm *tm_CurrentTime,
Gbl.UniqueNameEncrypted[1],
&Gbl.UniqueNameEncrypted[2], // 41 rightmost chars from a unique 43 chars base64url codified from a unique SHA-256 string
FilenameReport,Permalink);
DB_QueryINSERT (Query,"can not create new report");
DB_QueryINSERT (Query,"can not create new user's usage report");
}
/*****************************************************************************/
@ -1205,3 +1207,66 @@ static void Rep_DrawBarNumHits (float HitsNum,float HitsMax,
}
fprintf (Gbl.F.Rep,"<br />");
}
/*****************************************************************************/
/********** Remove all user's usage report of a user from database ***********/
/*****************************************************************************/
void Rep_RemoveUsrUsageReports (long UsrCod)
{
/***** Remove all user's usage report files of a user *****/
Rep_RemoveUsrReportsFiles (UsrCod);
/***** Remove all user's usage reports of a user from database *****/
Rep_RemoveUsrReportsFromDB (UsrCod);
}
/*****************************************************************************/
/********** Remove all user's usage reports of a user from database **********/
/*****************************************************************************/
static void Rep_RemoveUsrReportsFiles (long UsrCod)
{
char Query[128];
MYSQL_RES *mysql_res;
MYSQL_ROW row;
unsigned NumReports;
unsigned NumReport;
char PathUniqueDirReport[PATH_MAX+1];
/***** Get directories for the reports *****/
sprintf (Query,"SELECT UniqueDirL,UniqueDirR FROM usr_report"
" WHERE UsrCod='%ld'",
UsrCod);
NumReports = (unsigned) DB_QuerySELECT (Query,&mysql_res,"can not get user's usage reports");
/***** Remove the reports *****/
for (NumReport = 0;
NumReport < NumReports;
NumReport++)
{
/* Get next report */
row = mysql_fetch_row (mysql_res);
/* Remove report directory and file */
sprintf (PathUniqueDirReport,"%s/%s/%s/%s",
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_REP,row[0],row[1]);
Fil_RemoveTree (PathUniqueDirReport);
}
/***** Free structure that stores the query result *****/
DB_FreeMySQLResult (&mysql_res);
}
/*****************************************************************************/
/********** Remove all user's usage reports of a user from database **********/
/*****************************************************************************/
static void Rep_RemoveUsrReportsFromDB (long UsrCod)
{
char Query[128];
/***** Insert a new user's usage report into database *****/
sprintf (Query,"DELETE FROM usr_report WHERE UsrCod='%ld'",UsrCod);
DB_QueryDELETE (Query,"can not remove user's usage reports");
}

View File

@ -43,4 +43,6 @@ void Rep_ReqMyUsageReport (void);
void Rep_ShowMyUsageReport (void);
void Rep_PrintMyUsageReport (void);
void Rep_RemoveUsrUsageReports (long UsrCod);
#endif

View File

@ -213,7 +213,7 @@ void ZIP_CreateZIPAsgWrk (void)
Lay_ShowErrorAndExit ("Can not compress files into zip file.");
/***** Remove the directory of compression *****/
Brw_RemoveTree (Path);
Fil_RemoveTree (Path);
}
/*****************************************************************************/
@ -457,7 +457,7 @@ static void ZIP_CompressFolderIntoZIP (void)
}
/***** Remove the directory of compression *****/
Brw_RemoveTree (PathCompression);
Fil_RemoveTree (PathCompression);
}
/*****************************************************************************/