This is a patch file for "treesize" 0.54.1. It makes the following changes: a. If the user selects the root directory, a warning message is displayed. The message advises the user that the specified operation may take a long time. b. Traversal of "/proc" and "/sys" is blocked. This prevents some lockups and/or crashes. --- treesize-0.54.1.old/src/FAfolderAnalyzer.c +++ treesize-0.54.1/src/FAfolderAnalyzer.c @@ -90,7 +90,7 @@ int numSubFiles=0; int numSubFolders=0; - DIR *dirFD; + DIR *dirFD = 0; struct dirent *dirEnt; bool accessible=true; @@ -98,6 +98,14 @@ char *dirPath; if( ! TSrunning ) return false; + dirPath = makeDirPath (dirName, father); + + // Handle two special cases + if (!strcmp (dirPath, "/proc") || + !strcmp (dirPath, "/sys" )) + { + return false; + } /* let's go to the directory! */ if( chdir( dirName ) == -1 ) { @@ -110,8 +118,6 @@ perror( dirName ); } - dirPath= makeDirPath( dirName, father ); - /* printf("dirName [%s] , dirPath [%s]\n" , dirName , dirPath ); */ *newFolderInfo=thisFolderInfo=FInew( dirPath , dirStat , accessible , father ); @@ -155,7 +161,8 @@ sizeof( thisFolderInfo ) , folderSorter ); } - closedir( dirFD ); + + if (dirFD) closedir (dirFD); if( father ) chdir( FIgetPath( father )); return accessible; } @@ -212,8 +219,14 @@ char absoluteDirName[MAX_DIR_NAME]; FAgetFolderAbsoluteName(dirName, absoluteDirName, &dirStat, GO_TO_FOLDER); /* printf("%s %s\n" , __FUNCTION__ , dirName ); */ - /* puts( absoluteDirName ); */ + // Handle two special cases + if (!strcmp (absoluteDirName, "/proc") || + !strcmp (absoluteDirName, "/sys" )) + { + return 0; + } + ok = FAanalyzeRec(absoluteDirName, &dirStat, 0, &rootFolder, onlyOneFileSystem); /* FIprint( rootFolder ); */ --- treesize-0.54.1.old/src/TStreeSizeGui.c +++ treesize-0.54.1/src/TStreeSizeGui.c @@ -158,10 +158,11 @@ FolderInfo theFolder = FAanalyze( folder , onlyOneFileSystem ); - if( !TSrunning ){ - FIfree( theFolder ); - return 0; - } + if (!TSrunning || !theFolder) + { + FIfree (theFolder); + return 0; + } treeStore = gtk_tree_store_new(NUM_COLS, G_TYPE_INT , /* COL_PORCENT */ @@ -245,11 +246,12 @@ } - if( !TSrunning ){ /* were we aborted ? */ - gtk_widget_set_sensitive (btnCancel, FALSE); - pthread_mutex_unlock(&mutexCalcSize); - return; - } + if (!TSrunning || !treeStoreModel) + { // Operation aborted + gtk_widget_set_sensitive (btnCancel, FALSE); + pthread_mutex_unlock (&mutexCalcSize); + return; + } gtk_tree_view_set_model(GTK_TREE_VIEW( treeView ), treeStoreModel); @@ -263,6 +265,52 @@ void TScalculateSize( GtkWidget *treeView , char *folderName ){ +//-------------------------------------------------------------------- + + if (!strcmp (folderName, "/")) + { + gint response; + + GtkWindow *mainWindow = + (GtkWindow *) lookup_widget (treeView, "mainWindow"); + + GtkWidget *dialog = gtk_message_dialog_new + ( + mainWindow, GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_WARNING, GTK_BUTTONS_OK_CANCEL, + "Entire system is selected - This may take 15 minutes or longer in some cases!" + ); + + gtk_window_set_title (GTK_WINDOW(dialog), "Warning"); + response = gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + if (response == GTK_RESPONSE_CANCEL) return; + } + +//-------------------------------------------------------------------- + + if (!strcmp (folderName, "/proc") || + !strcmp (folderName, "/sys")) + { + GtkWindow *mainWindow = + (GtkWindow *) lookup_widget (treeView, "mainWindow"); + + GtkWidget *dialog = gtk_message_dialog_new + ( + mainWindow, GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, + "%s is a special case - Inadvisable to start there", + folderName + ); + + gtk_window_set_title (GTK_WINDOW(dialog), "Error"); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + return; + } + +//-------------------------------------------------------------------- + if( !FAgetFolderAbsoluteName( folderName , p.absoluteDirName , 0 , 1 ) ){ GtkWindow *mainWindow = (GtkWindow *) lookup_widget( treeView , "mainWindow" ); GtkWidget *dialog = gtk_message_dialog_new ( mainWindow ,