How to Design the recycle bin in Linux

Source: Internet
Author: User
The design concept of the recycle bin in Linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. I have been learning Linux for a while. Initially, to better learn Linux, ghost installed the original WinXp and fedora 7, but in the end, I can't help but unload it (I think Linux as a desktop system will probably know why) and download the VM in Xp. Because the configuration is not high, it is very difficult for my computer to run the VM (not as fast as the snail bait, sweat). Therefore, all operations that can be performed in the text mode should be performed in the text mode as much as possible.

A few days ago, I accidentally deleted a very important file. After being depressed for S, I finally decided to write a recycle bin that can be operated in text mode.

Function introduction:
Insert photo

Recycle. setup: Install the recycle bin program and create corresponding folders and files.

Recycle. uninstall: uninstall the recycle bin

Recycle. clean: Clear the user's recycle bin

Recycle. del file1 file2... Filen: delete file file1, file2... Filen and move it to the recycle bin

Recycle. restore file1 file2... Filen: Restore file file1, file2... Filen

Recycle. show: displays information in the user recycle bin.

Workflow:
1. delete a file or folder (recycle. del)

When a user wants to delete a file, the system calls rename to move the file to the root directory (/. recycle/) of the recycle bin, and restore the file as needed. There are some problems: first, you may delete files with the same file name. Obviously, we cannot put them together in the/. recycle folder. Secondly, because Linux is a multi-user operating system, a user (root out) does not have the permission to access or modify the content in the recycle bin of others.

For the first problem, we can do this: After the user deletes the file, instead of directly moving it to the recycle bin, we rename the deleted file according to the pre-defined naming method and then move it to the recycle bin. Create a text file infotable in the recycle bin directory and save the following information: original path, renamed file name, and deleted date. When deleting a file, register a new record with infotable. If the file is successfully registered, move the file to the recycle bin and rename it as a new file name. To get a new file name that is not repeated, create a new text file avaitable, which stores a set of values (such as:, 22 ......), Indicates that the new deleted files can use these values as new file names and ensure they are not duplicated.

For security, we can create a folder for each user and name it the user's ID. The attributes of the folder are "drwx ------", and their infotable and avaitable are saved under each folder.

2. restore a file or folder (recycle. restore)

The user tells the restoration program to restore the new file name with the same parameters. The restoration program searches for its original path in the infotable table and moves it back to the path; append the new file name to the avaitable file (indicating that the file name can be used), and finally Delete the relevant records in the infotable file.

3. Installation and initialization (recycle. setup)

First, root allows the recycle. setup program. This program creates a/. recycle folder (mode = 0777) and copies the recycle bin program to the/usr/bin directory.

A common user must first run recycle when using it for the first time. according to the user ID in /. create a subfolder under recycle, create an empty infotable and avaitable file, and write the agreed numbers to the avaitable file. Data is separated by line breaks.

4. display the recycle bin information (recycle. show)

The user enters the reclcye. show command, and the program displays the information needed by the user to read the infotable file.

5. clear the user recycle Bin (recycle. clear)

Each user only has the right to clear his/her recycle bin. First, the user's ID is obtained, then the user is deleted in the/. recycle folder, and finally the avaitable and infotable files are re-critical.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.