File Manager Delete to Trash instead of immediate removal (SKINS)

Version 1.61.0

Feature
Finished

New File Manager feature that moves files/folders to the ~/.trash directory when deleted, rather than immediately removing them from disk. The related filemanager_disable_features number for "trash" is 65536. "fm_settings" will now include: "trash": "1" "trash": "0" depending if the feature is enabled or not. New directadmin.conf option, internal default: fm_purge_trash_days=30 which indicates the age of days a file before being deleted. For folders, the last modified time of a folder must be >= 30 days old for it to be traversed. Valid values: -1 never auto-purge 0, immediately purge if found up to a max of 10000 days before being purged. ========= TO TRASH When deleting a file/folder, if the "trash=yes" option is included, the item will be move from /some/path.txt to /.trash/files//path.txt This will follow the freedestop.org trash specification: https://specifications.freedesktop.org/trash-spec/trashspec-1.0.html If there is a duplicate file in .trash/files/path.txt, the trash file is instead moved to .trash/files/path.txt.1 A related info file will be created in .trash/info/path.txt.trashinfo or (.trash/info/path.txt.1.trashinfo depending on how it was saved). The info file contains the Path and DeletionDate, which points to the original location (excludng any .1), and when it was deleted. Similar behavior for directories, where deleting a dir to trash moves it to .trash/files/dir or .trash/files/dir.1 if it already exists. Each delete-to-trash operation creates it's own instance. Deleting the same file over and over again creates a new copy, each of which can be restored. When viewing /.trash in the Filemanager, DA will not show you what's actually there, but the listing of "Path" items file/dir names from the .trashinfo file. There may be duplicates here. ========= RESTORE Restoring the /.trash/files/* data simply renames it to where it came from. If any parent folder is missing, the path will be created as 755. The value given to DA to do the restore MUST be the /.trash/files/file.txt.1 path, and not the "visible" /.trash/file.txt, as that does not exist. DA needs to reference the data file, which does not always match the original filename, as there may be duplicates. Per file can be: CMD_FILE_MANAGER/.trash/files/file.txt.1?action=restore For mass restore, very similar to the POST Delete button in the Filemanager, except you can pass: restore=<anytext> or button=restore along with each select0=/.trash/files/file.txt you want to restore, and "path=/.trash" ========= AUTO-DELETE Any tally, "all" or per-User, which affects disk usage, eg: action=tally&value=all action=tally&value=fred&type=user|reseller action=quotatally&value=all action=quotatally&value=fred=all&type=user|reseller will run the fully trash clean on either all Users (value=all) or on just that User (value=fred&type=user|reseller) PRIOR to running the repquota dump. This means that the trash is cleared before DA reads the total disk usage used, so usage shown is kept correct. ========= TASK QUEUE echo 'action=delete&value=trash' >> /usr/local/directadmin/data/task.queue echo 'action=delete&value=trash&username=fred' >> /usr/local/directadmin/data/task.queue ========= JSON the fm_settings and api_flags per-file will include new info for "trash=0|1". The api_flags for a given file will let you know if that file is in the trash, so if it should have a "restore" button beside it. The mask for trash is: #define FM_F_TRASH 65536 which can be used both with filemanager_disable_features but also binary-added into the api_flags. The call to: CMD_FILE_MANAGER?json=yes&action=json_all&path=%2F.trash&ipp=50 is "fake" in that is returns, for example (a directory called "delete"), where the index is what should be shown, but the "truepath" is where all actions and restores should be sent from. So the restore must use the truepath, not the index. { "/.trash/delete": { "api_flags": "65542", "date": "1589524902", "gid": "evoboss", "islink": "0", "linkpath": "", "name": "delete", "permission": "775", "showsize": "8.00k", "size": "8192", "truepath": "/.trash/files/delete", "uid": "evoboss", "type": "directory", "mtime": "1589524873", "atime": "1589524902", "sub_directories": "-1", "files": "0" } , "/.trash/delete.1": { "api_flags": "65542", "date": "1589525934", "gid": "evoboss", "islink": "0", "linkpath": "", "name": "delete.1", "permission": "775", "showsize": "8.00k", "size": "8192", "truepath": "/.trash/files/delete.1", "uid": "evoboss", "type": "directory", "mtime": "1589524873", "atime": "1589525935", "sub_directories": "-1", "files": "0" } ... Also, we should only show the "restore" button for the files/foldres in the /.trash listing. Assuming the truepath is used to navigate into delete directories (which is allowed), then should not see a restore button on, for example: /.trash/files/delete/test.html but they can delete the test.html, should they wish to clear it from the trash ahead of time. (use the truepath, but here it should match). The items in the listing of /.trash should also have a delete button, where DA will notice is a trash-deleted-item, and will also cleanup the /.trash/info/delete.trashinfo file as well. ========= SKINS Enhanced/Power User: New IMG_TRASH icon for the /.trash directory. img/trash.png ---- EVO1844 T26527

Interested to try DirectAdmin? Get a 30-day Free Trial!