Data deletion method and computer equipment
By prioritizing the reading of the target deletion function in the target dynamic library and choosing the appropriate deletion method, the problem of data loss in data deletion operations that do not support the recycling bin mechanism is solved, and a simple and efficient recycling bin mechanism is realized, which is compatible with direct deletion operations.
Patent Information
- Application Number
- CN202411931040.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-04-25
- Estimated Expiration
- 2044-12-25
AI Technical Summary
The existing data deletion operation that does not support the recycling bin mechanism can easily lead to false deletion and permanent loss of important data, and the method of implementing the recycling bin mechanism is complex and inefficient.
By prioritizing the reading of the target deletion function in the target dynamic library, modify the direct deletion behavior based on the original dynamic library, and select the appropriate target deletion method (direct deletion or protection deletion based on the recycling bin mechanism) to perform the data deletion operation.
It realizes the simple and efficient implementation of the recycling bin mechanism in the process of data deletion that does not support the recycling bin mechanism, and is compatible with direct deletion operations, improving data security and operation flexibility.
Smart Images

Figure CN119883116A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of computer technology, and in particular, relates to a data deletion method and a computer device. Background Art
[0002] The deletion commands provided by some mainstream operating systems in the industry currently do not support the Recycle Bin mechanism, such as the deletion commands of the Linux operating system distribution. When using deletion commands that do not support the Recycle Bin mechanism to delete data, important data may be accidentally deleted, resulting in permanent deletion and loss of data.
[0003] In the related art, in order to implement the recycle bin mechanism of the delete command, on the one hand, specific tool software can be used and corresponding specific commands can be used to implement it, such as installing the Trash-CLI command line tool, etc. On the other hand, the recycle bin mechanism can be implemented by modifying the content of the delete command itself. The implementation method of the recycle bin mechanism in the above data deletion process is complex and inefficient. Summary of the invention
[0004] The embodiments of the present application provide a data deletion method and a computer device, which can implement a simple and efficient recycle bin mechanism in a data deletion operation that does not support the recycle bin mechanism.
[0005] A first aspect of an embodiment of the present application provides a data deletion method, including:
[0006] In response to a delete command for target data, a target delete function is called, wherein the target delete function is contained in a target dynamic library, and the read priority of the target dynamic library is higher than that of the original dynamic library;
[0007] In the process of calling the target deletion function, identifying the target deletion mode of the target data;
[0008] If the target deletion method is a protection deletion based on a recycle bin mechanism, then a protection deletion operation is performed on the target data;
[0009] If the target deletion method is direct deletion, the original deletion function is called to directly delete the target data, and the original deletion function is included in the original dynamic library.
[0010] By preferentially reading the target deletion function in the target dynamic library, the program behavior originally implemented by the original deletion function based on the original dynamic library is modified to the program behavior implemented by the target deletion function based on the target dynamic library, and the appropriate target deletion method is selected from the direct deletion method or the protection deletion method based on the recycle bin mechanism to perform the data deletion operation. In this way, it is not only compatible with the direct deletion operation based on the original dynamic library, but also can implement a simple and efficient recycle bin mechanism in the data deletion process that does not support the recycle bin mechanism.
[0011] In an implementation manner of the first aspect, before calling the target deletion function, the method further includes:
[0012] Acquire a newly added dynamic library, wherein the newly added dynamic library includes the target deletion function;
[0013] Compiling the newly added dynamic library through a compiler to obtain the target dynamic library;
[0014] The target dynamic library is written into a preload file of the linker, and the reading priority of the preload file is higher than other loading directories of the linker.
[0015] By configuring the target dynamic library in the preload file with high reading priority, the target dynamic library is read before the original dynamic library, so that the target deletion function of the target dynamic library is called before the original deletion function. In this way, the data deletion operation based on the recycle bin mechanism can be implemented without changing any content of the original dynamic library.
[0016] In an implementation of the first aspect, calling the target deletion function includes:
[0017] The target dynamic library is read according to the preload file.
[0018] In the target dynamic library, the target deletion function is read and called.
[0019] In an implementation of the first aspect, in the process of calling the target deletion function, identifying the target deletion method of the target data includes:
[0020] Reading configuration information corresponding to the deletion mode from the configuration file, the configuration information including a specified flag bit, the specified flag bit being used to indicate whether a recycle bin mechanism is globally enabled;
[0021] If the designated flag indicates that the recycle bin mechanism is globally enabled, then the target deletion method of the target data is determined to be protective deletion based on the recycle bin mechanism.
[0022] Whether to enable the recycle bin mechanism is dynamically controlled by specifying a flag in the configuration information, and the deletion method can be flexibly adjusted according to actual conditions, thereby improving operational flexibility and user experience.
[0023] In an implementation manner of the first aspect, the configuration information further includes at least one protected directory for which a recycle bin mechanism needs to be enabled, and the method further includes:
[0024] If the specified flag indicates that the recycle bin mechanism is not enabled globally, matching the target data with any of the protection directories to obtain a matching result;
[0025] If the matching result indicates that there is a protection directory that matches the target data, determining that the target deletion method of the target data is a protection deletion based on a recycle bin mechanism;
[0026] If the matching result indicates that there is no protection directory matching the target data, it is determined that the target deletion method of the target data is direct deletion.
[0027] By matching the target data with the protection directory in the configuration information, the accuracy of determining the deletion method for the target data is improved.
[0028] In an implementation of the first aspect, the performing of the protection deletion operation on the target data includes:
[0029] Backing up the target data based on a preset recycle bin directory;
[0030] If the target data is backed up successfully, then in the original directory of the target data, the original deletion function is called to perform a direct deletion operation on the target data.
[0031] By backing up the target data in the preset recycle bin directory and performing a direct deletion operation after the backup is successful, you can effectively prevent the permanent loss of important data and improve data security.
[0032] In an implementation of the first aspect, the backing up the target data based on a preset recycle bin directory includes:
[0033] Saving attribute information of the target data;
[0034] Packing and compressing the target data through a compression command to obtain a compressed package of the target data;
[0035] The compressed package is stored in a preset recycle bin directory.
[0036] By saving the attribute data of the target data, packaging and compressing it, and storing the compressed package in a preset recycle bin directory, not only can the integrity of the data be protected, but also the storage efficiency can be improved.
[0037] In an implementation of the first aspect, the method further includes:
[0038] If a recovery command for any data to be recovered in the recycle bin directory is received, a compressed package of the data to be recovered is obtained based on the identifier of the data to be recovered;
[0039] The compressed package is decompressed to obtain the data to be restored.
[0040] By quickly locating and decompressing a specified compressed package based on an identifier to restore the data to be restored, the efficiency and reliability of data recovery can be improved.
[0041] In an implementation of the first aspect, before reading configuration information corresponding to the deletion mode from the configuration file, the method further includes:
[0042] Obtaining a triggering method for the deletion command;
[0043] If the trigger mode is consistent with the preset trigger mode, reading configuration information corresponding to the deletion mode from the configuration file, and identifying the target deletion mode of the target data based on the configuration information;
[0044] If the trigger mode is inconsistent with the preset trigger mode, the original deletion function is called to perform the data deletion operation.
[0045] By verifying the consistency between the triggering mode of the deletion command and the preset triggering mode, strict control over the deletion operation can be achieved, thereby enhancing the security of the system and reducing the risk of misoperation.
[0046] A second aspect of an embodiment of the present application provides a data deletion device, including:
[0047] A loading module, configured to call a target deletion function in response to a deletion command for target data, wherein the target deletion function is included in a target dynamic library, and a reading priority of the target dynamic library is higher than that of an original dynamic library;
[0048] An identification module, used for identifying a target deletion mode of the target data in the process of calling the target deletion function;
[0049] A protection deletion module, configured to execute a protection deletion operation on the target data if the target deletion mode is a protection deletion based on a recycling bin mechanism;
[0050] The direct deletion module is used to call the original deletion function to directly delete the target data if the target deletion method is direct deletion, and the original deletion function is included in the original dynamic library.
[0051] A third aspect of an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect when executing the computer program.
[0052] A fourth aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method described in the first aspect above is implemented.
[0053] In the first aspect of the embodiment of the present application, during the running of the application, the program behavior originally implemented by the original deletion function based on the original dynamic library is modified to the program behavior implemented by the target deletion function based on the target dynamic library by preferentially reading the target deletion function in the target dynamic library, and a suitable target deletion method is selected from the direct deletion method or the protection deletion method based on the recycle bin mechanism to perform the data deletion operation. In this way, not only is it compatible with the direct deletion operation based on the original dynamic library, but also a simple and efficient recycle bin mechanism can be implemented in the data deletion process that does not support the recycle bin mechanism.
[0054] It can be understood that the beneficial effects of the second to fourth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0056] Figure 1 is a flowchart of the implementation of the data deletion method provided in the embodiment of the present application;
[0057] Figure 2 is an example diagram of configuration information for a deletion method provided in an embodiment of the present application;
[0058] Figure 3 is a flow chart of the implementation of the target dynamic library loading method provided in the embodiment of the present application;
[0059] Figure 4is a flowchart of a method for determining a target deletion mode provided in an embodiment of the present application;
[0060] Figure 5 is another implementation flow chart of the method for determining the target deletion mode provided in the embodiment of the present application;
[0061] Figure 6 This is a flowchart of the implementation of the protection deletion operation provided in the embodiment of the present application;
[0062] Figure 7 is a flowchart of the implementation of the data recovery operation provided by the embodiment of the present application;
[0063] Figure 8 This is a flowchart of implementing data deletion adapted to the triggering method provided in the embodiment of the present application;
[0064] Fig. 9 This is a data deletion implementation flow chart adapted for the rm command provided in an embodiment of the present application;
[0065] Fig.10 This is a flowchart of implementing the recycle bin mechanism using the rm command provided in the embodiment of the present application;
[0066] Fig.11 is a schematic diagram of a data deletion device provided in an embodiment of the present application;
[0067] Fig.12 It is a schematic diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0068] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0069] 1) Dynamic link library, also known as dynamic library (Dynamic Library), also known as shared library (Shared Library), is a library file that is loaded when the program is running. When updating the code of the library file, there is no need to recompile and link the application that depends on the library. Dynamic libraries have different suffixes in different operating systems, such as .dll files in Windows, .so files in Unix / Linux, and .dylib files in macOS.
[0070] 2) Linker: A tool that combines one or more object files and library files into an executable file, shared library, or other object file. The linker runs in the post-compilation phase and completes tasks such as symbol resolution, relocation, and code merging.
[0071] 3) System call: It is a set of interfaces provided by the operating system, allowing applications in user space to request services from the kernel space of the operating system. System calls are used to perform low-level operations, such as file operations, process control, network communication, etc. It is a bridge between the operating system and applications, ensuring that applications can use system data safely and efficiently.
[0072] 4) GNU C Library: GNU C Library is an open source standard C library implementation that provides the POSIX standard and some additional GNU extensions. glibc is a core component of the Linux operating system. It provides basic system call interfaces, standard I / O operations, string processing, memory management and other functions, and is an important basis for building and running C programs.
[0073] 5) Executable and Linkable Format (ELF): is a standard file format for storing executable files, object codes, shared libraries, and core dumps. The target deletion function of the ELF file has the same name as the original function in the original dynamic library. In applications, target data refers to the data to be deleted stored in the file system of a computer device, such as files, directories, etc. In response to a deletion command for the target data, the process of the application usually loads the original deletion function in the original dynamic library to perform data deletion processing. Among them, the implementation process of performing data deletion based on the original deletion function of the original dynamic library is as follows: During the running of the application, in response to a deletion command for the target data, the original dynamic library is first read through the linker and the original deletion function in the original dynamic library is loaded into the address space of the application, and the starting address of the original deletion function is returned. The process locates to the starting address and starts to execute the code fragment of the original deletion function to perform data deletion operations.
[0074] It should be noted that since the data deletion method based on the original deletion function of the original dynamic library does not support the Recycle Bin mechanism (i.e., a method for temporarily saving deleted data that can be restored before the deleted data is finally deleted), a target dynamic library that supports the Recycle Bin mechanism is provided in advance for data deletion scenarios that need to support the Recycle Bin mechanism, and a dynamic interception method is used to ensure that the target dynamic library is read before the original dynamic library. The essence of the dynamic interception method is to adjust the program behavior of the original deletion function that originally reads the original dynamic library to perform the deletion operation to the program behavior of the target deletion function that reads the target dynamic library to perform the deletion operation during program execution. The target deletion function in the target dynamic library that is read first is called before the original deletion function in the original dynamic library.
[0075] In the application, the target dynamic library is used to replace the original dynamic library to implement the data deletion operation based on the recycle bin mechanism. The target dynamic library includes the target deletion function. In order not to modify the existing code for calling the deletion function of the application, the program behavior of executing the original deletion function in the original dynamic library can be converted to the program behavior of executing the target deletion function in the target dynamic library by only preferentially reading the target dynamic library. It is necessary to ensure that the target deletion function has the same name as the original deletion function. If the original deletion function includes parameters, the target deletion function must also include the same parameters. That is, the definition of the target deletion function is consistent with that of the original deletion function, and the difference is that the specific business logic of the target deletion function and the original deletion function to implement data deletion is different.
[0076] Exemplarily, the application receiving the deletion instruction runs in the Linux operating system, and the Linux operating system provides the unlinkat system call to implement the data deletion operation. Unlinkat is a system call in Unix and Unix-like operating systems (such as Linux), which is used to delete files or directory entries. The Linux operating system provides the original dynamic library glibc.so, which provides the original deletion function unlinkat(), which encapsulates the unlinkat system call. The deletion command is triggered by inputting "rm [pathname]" through the command line tool provided by the Linux system. The process of the application receives the deletion command for the target data (the data indicated by [pathname]), dynamically loads the original dynamic library glibc.so, and searches for the original deletion function unlinkat() from the loaded dynamic library in turn, and returns the address of the original deletion function unlinkat() in the address space of the application. At the same time, the address can be written into the Global Offset Table (GOT) table, so that the address of the original delete function unlinkat() can be found from the GOT table next time to avoid multiple addressing overheads. Each entry in the GOT table represents the correspondence between a single external symbol and the address of the external symbol. Here, the original delete function unlinkat() can be used as an external symbol, and the address of the original delete function unlinkat() is written into the GOT table. Then, the process locates to the address and starts to execute the original delete function unlinkat() to complete the data deletion process.
[0077] Based on the description, it can be known that the original delete function of the original dynamic library glibc.so cannot support the data deletion operation based on the recycling bin mechanism. Therefore, a target dynamic library new.so is provided, and the target dynamic library new.so encapsulates the target delete function, and the data deletion logic based on the recycling bin mechanism is added to the target delete function. The function name of the target delete function is the same as the function name of the original delete function, that is, the target dynamic library new.so provides the target delete function unlinkat(). The target delete function includes a code snippet that implements the data deletion operation based on the recycling bin mechanism.
[0078] Step S102, in the process of calling the target deletion function, identifying the target deletion method of the target data.
[0079] In the application, the process of the application locates the starting address of the target deletion function in the address space, and executes the business logic of the target deletion function from the starting address. In the process of executing the target deletion function, the target deletion method for the target data is identified. Among them, the deletion method refers to the specific deletion operation that needs to be performed on the data, and the deletion method includes at least one of the following: direct deletion method, protection deletion method based on the recycle bin mechanism. Direct deletion refers to direct deletion from the file system. Protection deletion based on the recycle bin mechanism refers to a deletion method that temporarily saves deleted data and can be restored before final deletion.
[0080] In the application, determining the deletion method of data is essentially to determine whether to enable the recycle bin mechanism for the data. If the recycle bin mechanism is enabled for any data, the deletion method of the data is the protection deletion method based on the recycle bin mechanism. If the recycle bin mechanism is disabled for any data, the deletion method of the data is direct deletion.
[0081] In the application, the configuration method for configuring whether to enable the recycle bin mechanism for any data in the file system includes at least one of the following methods: file configuration method and global variable configuration method. The file configuration method refers to configuring at least one data that needs to enable the recycle bin mechanism in the configuration file. The global variable configuration method refers to configuring whether to enable the recycle bin mechanism by setting a global variable. It should be noted that for the global variable configuration method, the value of the global variable can also be changed by adding a global variable in the configuration file.
[0082] For example, taking the file configuration method as an example, the file system has Figure 2The configuration file conf shown in the figure has three directories for which the recycle bin mechanism needs to be enabled: " / root / SPECcpu / result", " / home / yoe / stream / result", and " / home / kvm / xml". That is, if the path of the target data to be deleted belongs to any of the above three directories, the deletion method for the target data is the protective deletion method based on the recycle bin mechanism.
[0083] Step S103: If the target deletion method is a protection deletion based on a recycle bin mechanism, a protection deletion operation is performed on the target data.
[0084] In the application, when it is determined that the target deletion method for the target data is a protection deletion based on a recycle bin mechanism, the process performs a protection deletion operation on the target data.
[0085] In applications, for protected deletion based on the recycle bin mechanism, a recycle bin directory for temporarily storing target data is usually pre-configured. The essence of a process performing a protected deletion operation is to move the target data to the recycle bin directory for temporary storage, and to delete the target data in the original directory of the target data, so that the target data cannot be obtained in any other directory in the file system except the recycle bin directory. It should be noted that in order to reduce the storage space occupied by the recycle bin directory, the target data can be compressed first and the resulting compressed package can be temporarily stored in the recycle bin directory.
[0086] Step 104: If the target deletion method is direct deletion, the original deletion function is called to directly delete the target data. The original deletion function is included in the original dynamic library.
[0087] In the application, if the target deletion method is direct deletion, the application process directly locates the starting address of the original deletion function and executes the logic of the original deletion function to directly delete the target data.
[0088] In this embodiment, during the running of the application, the data deletion behavior originally implemented based on the original deletion function in the original dynamic library is modified to be implemented based on the target deletion function in the target dynamic library by preferentially loading the target deletion function in the target dynamic library, and a suitable target deletion method is selected from the direct deletion method or the protection deletion method based on the recycle bin mechanism, and the data deletion operation adapted to the target deletion method is executed. In this way, not only is it compatible with the direct deletion operation based on the original dynamic library, but it can also implement a simple and efficient recycle bin mechanism in the data deletion process that does not support the recycle bin mechanism.
[0089] In one embodiment, Figure 3 As shown, the process of acquiring the target dynamic library includes the following steps S201 to S203:
[0090] Step S201, obtaining a newly added dynamic library, where the newly added dynamic library includes a target deletion function.
[0091] In the application, the target dynamic library is a newly added dynamic library, which is essentially a file. The process obtains the newly added dynamic library from the directory storing the newly added dynamic library through the file operation interface. The newly added dynamic library includes a target deletion function.
[0092] Step S202, compile the newly added dynamic library through a compiler to obtain a target dynamic library.
[0093] In the application, the compiler is called to compile the newly added dynamic library to obtain the target dynamic library. For example, for the dynamic library applied to the Linux operating system, the dynamic library can be compiled by the GCC compiler to obtain the target dynamic library.
[0094] Step S203, writing the target dynamic library into a preload file of the linker, the reading priority of the preload file is higher than other load files of the linker.
[0095] In the application, the dynamic library that the data deletion operation depends on is read through a linker, and the dependent dynamic library includes at least a target dynamic library and an original dynamic library.
[0096] In the application, the linker includes preload files and other load files. Both preload files and other load files can be used to configure dynamic libraries. The preload files are read before other load files, and the reading priority of the dynamic library configured in the preload file will also take precedence over the dynamic library configured in other load files.
[0097] In applications, the original dynamic library is usually configured in other loading files of the linker. Since the reading priority of other loading files is lower than that of the preloading file of the linker, in order to ensure that the target dynamic library can be read before the original dynamic library, the process directly writes the target dynamic library into the preloading file of the linker. In this way, when the linker is used to read the dynamic library that the deletion operation depends on, the content of the target dynamic library will be read first, and when the target deletion function is read, the address of the target deletion function in the address space of the application will be returned. For example, the preloading file of the linker in the Linux operating system is " / etc / ld.so.preload". When the target dynamic library is configured in " / etc / ld.so.preload", the target dynamic library in " / etc / ld.so.preload" will be read first.
[0098] In one embodiment, the specific implementation of calling the target deletion function based on the preload file is as follows: according to the preload file, read the target dynamic library; in the target dynamic library, read and call the target deletion function. In the application, the process first reads the configured target dynamic library from the preload file, then writes the target deletion function of the target dynamic library into the address space of the process, and finally executes the deletion logic of the target deletion function from the starting address of the target deletion function in the address space.
[0099] In this embodiment, by configuring the target dynamic library in the preload file with high reading priority, it is ensured that the target dynamic library is read before the original dynamic library, thereby ensuring that the target deletion function of the target dynamic library is called before the original deletion function. In this way, the data deletion operation based on the recycle bin mechanism can be implemented without changing any content of the original dynamic library.
[0100] In one embodiment, Figure 4 As shown, the implementation process of step S102 includes the following steps S301 to S302:
[0101] Step S301, reading configuration information corresponding to the deletion mode from a configuration file, the configuration information including a specified flag bit, the specified flag bit being used to indicate whether a recycle bin mechanism is globally enabled.
[0102] In the application, determining the data deletion method is essentially to determine whether to enable the recycle bin mechanism for the data. Whether to enable the recycle bin mechanism to delete the data can be configured through the file configuration method. The process reads the configuration information corresponding to whether to enable the recycle bin mechanism from the configuration file set by the file configuration method. The configuration information may include a specified flag bit for indicating whether the recycle bin mechanism is enabled globally. The specified flag bit is a global variable in the application. By setting different values for the specified flag bit in the configuration file, the value of the global variable is adjusted to identify whether the recycle bin mechanism is enabled globally.
[0103] like Figure 2 As shown, in the configuration file, the specified flag global_effect is set to indicate whether the recycle bin mechanism needs to be globally enabled. If global_effect = 0, it indicates that the recycle bin mechanism is not globally enabled. The process reads the corresponding global variable global_effect to determine that the recycle bin mechanism is not globally enabled. If global_effect = 1, it indicates that the recycle bin mechanism is globally enabled.
[0104] Step S302: If the designated flag indicates that the recycle bin mechanism is globally enabled, it is determined that the target deletion method of the target data is a protection deletion based on the recycle bin mechanism.
[0105] In the application, the process reads the specified flag bit. If the specified flag bit indicates that the recycle bin mechanism is globally enabled, the target deletion method for the target data is the protection deletion based on the recycle bin mechanism.
[0106] In this embodiment, whether to enable the recycle bin mechanism is dynamically controlled by a specified flag bit in the configuration information, and the deletion method can be flexibly adjusted according to actual conditions, thereby improving the flexibility of operation and user experience.
[0107] In one embodiment, Figure 5 As shown, the process of determining the target deletion method includes the following steps S401 to S405:
[0108] Step S401, reading configuration information corresponding to the deletion mode from a configuration file, the configuration information including a specified flag bit, the specified flag bit being used to indicate whether a recycle bin mechanism is globally enabled.
[0109] In the application, step S401 can refer to Figure 4 The description of step S301 in the embodiment is not repeated here.
[0110] Step S402: If the designated flag indicates that the recycle bin mechanism is globally enabled, it is determined that the target deletion method of the target data is a protection deletion based on the recycle bin mechanism.
[0111] In the application, step S402 can refer to Figure 4 The description of step S302 in the embodiment is not repeated here.
[0112] Step S403: if the designated flag indicates that the recycle bin mechanism is not enabled globally, the target data is matched with any protection directory to obtain a matching result.
[0113] In the application, the configuration information may also include at least one protected directory for which the recycle bin mechanism needs to be enabled. The protected directory refers to the directory for which the recycle bin mechanism needs to be enabled, that is, when deleting data matching the protected directory, the protected deletion method based on the recycle bin mechanism needs to be used. Therefore, when the designated flag indicates that the recycle bin mechanism is not enabled globally, the process configures the protected directory that needs to be protected deleted based on the recycle bin mechanism in the configuration file according to actual needs.
[0114] In the application, the process matches the target data with any protection directory in the configuration information to obtain a matching result to determine whether to perform a protection deletion operation based on the recycle bin mechanism on the target data. The matching of the protection directory and the target data means that the path of the target data belongs to the protection directory or a subdirectory of the protection directory.
[0115] Step S404: if the matching result indicates that there is a protection directory that matches the target data, then determining that the target deletion method of the target data is a protection deletion based on a recycle bin mechanism.
[0116] In the application, if the matching result indicates that there is a match between the protection directory and the target data, it means that the target data needs to be protected and deleted, that is, the protection deletion based on the recycle bin mechanism is used as the target deletion method of the target data. Figure 2 As shown, the three protection directories " / root / SPECcpu / result", " / home / yoe / stream / result", and " / home / kvm / xml" are configured. If the path of the target data belongs to any of the three protection directories, the protection deletion method based on the recycle bin mechanism is used to delete the target data.
[0117] Step S405: If the matching result indicates that there is no protection directory matching the target data, then the target deletion method of the target data is determined to be direct deletion.
[0118] In the application, when the matching result indicates that there is no match between the protection directory and the target data, that is, the path of the target data does not belong to any protection directory in the configuration file, the target data can be directly deleted, that is, direct deletion is used as the target deletion method of the target data.
[0119] In this embodiment, the accuracy of determining the deletion method for the target data is improved by matching the target data with the protection directory in the configuration information.
[0120] In one embodiment, Figure 6 As shown, Figure 1 The implementation process of step S103 includes the following steps S501 to S502. Among them:
[0121] Step S501, backing up the target data based on the preset recycle bin directory.
[0122] In an application, performing a protection deletion operation on target data is essentially to temporarily save the target data to a preset recycle bin directory to back up the target data in the recycle bin directory.
[0123] It should be noted that, in order to reduce the data occupancy of the recycle bin, the target data may be compressed, and the obtained data compression package may be temporarily stored in the recycle bin directory.
[0124] Step S502: If the target data is backed up successfully, then in the original directory of the target data, the original deletion function is called to perform a direct deletion operation on the target data.
[0125] In the application, after the target data is successfully backed up in the recycle bin directory, the target data is directly deleted in the original directory of the target data by executing the original deletion function.
[0126] In this embodiment, by backing up the target data in a preset recycle bin directory and performing a direct deletion operation after the backup is successful, permanent loss of important data can be effectively prevented and data security can be improved.
[0127] In one embodiment, the implementation process of the backup processing of the target data is as follows: save the attribute data of the target data, package and compress the target data through a compression command to obtain a compressed package of the target data, and store the compressed package in a preset recycle bin directory.
[0128] In the application, when performing protection deletion on the target data, the attribute data of the target data is saved, such as the time and path information of the current deletion operation, and the permission information of the deletion object. The target data is packaged and compressed through the compression command, and then the obtained compressed package is stored in the preset recycle bin directory.
[0129] In this embodiment, by saving the attribute data of the target data, packaging and compressing the target data, and storing the compressed package in a preset recycle bin directory, not only the integrity of the data can be protected, but also the storage efficiency can be improved.
[0130] In one embodiment, Figure 7 As shown, the implementation process of the data recovery method includes the following steps S601 to S602:
[0131] Step S601: if a recovery command for any data to be recovered in the recycle bin directory is received, a compressed package of the data to be recovered is obtained based on the identifier of the data to be recovered.
[0132] In the application, the data in the recycle bin directory is associated with a corresponding identifier, which is used to uniquely identify the compressed package of the data. The data temporarily stored in the recycle bin directory can be restored. Specifically, when the process receives a restore instruction for any data to be restored, it can search for the specified compressed package of the data to be restored from the storage space through the identifier carried in the restore instruction.
[0133] Step S602, decompress the compressed package to obtain the data to be restored.
[0134] In the application, the process decompresses the compressed package of the data to be recovered to obtain the data to be recovered.
[0135] In this embodiment, the data to be recovered is recovered by quickly locating and decompressing a specified compressed package based on the identifier, thereby improving the efficiency and reliability of data recovery.
[0136] In one embodiment, Figure 8 As shown, the process can implement a deletion process based on the recycle bin mechanism for the deletion command of the specified trigger mode, and the implementation process includes the following steps S701 to S703:
[0137] Step S701, obtaining a triggering method for a delete command.
[0138] In the application, the triggering method for the deletion command includes at least command triggering or application interface triggering. Command triggering refers to triggering the deletion command based on the operating system, such as entering the deletion command in the command line tool provided by the operating system, such as rm[pathname]. Application interface triggering refers to triggering the file deletion interface for file system operations based on the programming language that implements the application. For example, if the application is implemented in the Java programming language, the deletion command can be triggered when the file.delete interface in the java.io.File class is called in the application.
[0139] Step S702: If the trigger mode is consistent with the preset trigger mode, configuration information corresponding to the deletion mode is read from the configuration file, and the target deletion mode of the target data is identified based on the configuration information.
[0140] In the application, if it is determined that the triggering mode of the current deletion command is consistent with the preset triggering mode, the target deletion function is used to perform the deletion operation.
[0141] Step S703: If the trigger mode is inconsistent with the preset trigger mode, the original deletion function is called to perform the data deletion operation.
[0142] In the application, if you only need to protect and delete data for deletion instructions with a specific trigger method, you can preset the trigger method and determine whether the trigger method of the current deletion instruction is consistent with the preset trigger method. If they are inconsistent, use the original deletion function to perform the deletion operation. If they are consistent, use the target deletion function to perform the deletion operation.
[0143] For example, in a Linux system, the preset trigger mode is triggered by a delete instruction based on a command line tool, such as a delete command triggered by entering "rm [pathname]" in a command line tool. The process determines whether the executable file of the current process in / proc / self / exe is rm. If it is rm, it determines that the current trigger mode is consistent with the preset trigger mode, and the protective delete mode can be used to perform the delete operation.
[0144] In this embodiment, by verifying the consistency between the triggering mode of the deletion command and the preset triggering mode, strict control over the deletion operation can be achieved, thereby enhancing the security of the system and reducing the risk of misoperation.
[0145] In one embodiment, the data deletion method provided in the embodiment of the present application implements the recycle bin mechanism of the rm command of the Linux operating system as an example for explanation. Fig. 9 As shown in the figure, after the user executes the rm command in the command line tool, the unlinkat library function will be called to implement the deletion. In the original unlinkat logic, the dynamic library is intercepted and loaded, and the business logic code for implementing the recycle bin mechanism is added to implement the recycle bin mechanism. The logic diagram from user input to execution of the deletion scenario is as follows (the dotted line is the original process).
[0146] exist Fig. 9 In the example, the user enters the rm command in the command line tool, and the process starts to execute the deletion task: calling the original deletion function unlinkat() in the original dynamic library glibc. The unlinkat() function encapsulates the unlinkat system call provided by the Linux operating system. When the operating system falls into the kernel, it will perform data deletion operations at the file system level. In order to add protection deletion based on the recycling bin mechanism to the rm command, the loading interception of the original dynamic library is implemented through the mechanism of loading during the execution of the dynamic library, thereby changing the program behavior, so that the program behavior that should load the original dynamic library and call the original deletion function in the original dynamic library to delete data is replaced by the program behavior of loading the target dynamic library and calling the target deletion function in the target dynamic library to perform protection deletion based on the recycling bin mechanism. The data deletion logic based on the recycling bin mechanism is added to the target deletion function, and the protection deletion of the target data can be performed when the data recovery conditions are met.
[0147] In the application, the main execution process of deleting functions based on execution goals is as follows Fig.10 As shown, it includes steps S801 to S805:
[0148] Step S801, detecting whether it is a deletion command triggered by a specified triggering method.
[0149] In the application, the deletion command using the system call unlinkat can be triggered not only by the rm command, but also by other programs. The process detects whether the rm deletion command is triggered based on the command line tool. Specifically, it can be determined by judging whether the executable file of the current process in / proc / self / exe is the rm command.
[0150] If the detection result is yes, then execute the following step S802, and if the detection result is no, then execute the following step S805.
[0151] Step S802: Read configuration information from a specified configuration directory.
[0152] In the application, the process reads the configuration directory for implementing the protection deletion of the recycle bin mechanism and reads the configuration information from the configuration file. The configuration information includes the specified flag and the protection directory. The specified flag indicates whether the recycle bin mechanism is enabled globally. The configuration information in the configuration file is as follows: Figure 2 shown.
[0153] Step S803: Based on the specified flag bit and the protection directory included in the configuration information, it is detected whether the recycle bin mechanism is enabled for the target data.
[0154] In the application, the process first determines the value of the specified flag. If the specified flag indicates that the recycle bin mechanism is enabled globally, there is no need to match the protection directory, and the recycle bin mechanism can be enabled for the target data. If the specified flag indicates that the recycle bin mechanism is not enabled globally, the target data is matched with any protection directory. If the match is successful, the recycle bin mechanism is started for the target data. If the match is unsuccessful, the original deletion function is used to directly delete the logic.
[0155] If the detection result is that the recycle bin mechanism is enabled, the following step S804 is executed; if the detection result is that the recycle bin mechanism is not enabled, the following step S805 is executed.
[0156] Step S804: Execute a protection deletion operation based on the recycle bin mechanism.
[0157] In the application, if it is determined that a recycle bin mechanism is started for target data, a protection deletion operation based on the recycle bin mechanism is performed on the target data.
[0158] Step S805, calling the original deletion function in the original dynamic library to execute direct deletion of the target data.
[0159] In the application, the original deletion function in the original dynamic library is directly called to perform direct deletion of the target data.
[0160] For example, when using the SPECcpu tool for testing, the test result archive directory is " / home / cpu2018 / result", and a protection deletion operation based on the recycle bin mechanism is implemented for the data under " / home / cpu2018 / result": First, before performing the protection deletion operation, deploy the dynamic library and enable the configuration. The specific deployment plan can be integrated into the rpm software package, and can be deployed with one click using the rpm-ivh command. Add the " / home / cpu2018 / result" directory as a protection directory in the specified configuration directory / home / cpu2018 / conf to enable the recycle bin mechanism for the " / home / cpu2018 / result" directory. Or set the indicator flag global_effect to 1 to indicate that the recycle bin mechanism is enabled globally. Next, after enabling the recycle bin mechanism for " / home / cpu2018 / result", execute the command "rm-rf*" in the command line tool. All data in " / home / cpu2018 / resul" is moved to the recycle bin directory / home / .rm_trash, and " / home / cpu2018 / resul" is emptied.
[0161] In the application, if you need to restore deleted data, you can search for the data to be restored in the recycle bin directory " / home / .rm_trash" by using the data packet identifier. The data packet identifier is used to uniquely identify the data compression package of the data. The data packet identifier can contain the time when the deletion occurred, the absolute path of the deleted data, etc. Then, decompress the searched data packet to obtain the previously deleted data. At this time, the data deleted by the rm command is restored.
[0162] In this embodiment, the dynamic library configuration can be effective for a long time after being written, and any scenario calling the rm command can be intercepted and effective. There is no need to start a new process or script, and insert business code into the original code logic, avoiding a lot of performance overhead. In addition, through the relationship between the rm command and the unlinkat system call (the rm command encapsulates the unlinkat system call), the recycle bin function is added to the rm command. The recycle bin mechanism is established in the original command rm, which is simple and convenient for users to use.
[0163] The present application also provides a data deletion device for executing the steps in the above robot control method embodiment. Fig.10 As shown, the data deletion device 900 provided in the embodiment of the present application includes:
[0164] The loading module 910 is used to call a target deletion function in response to a deletion command for target data. The target deletion function is included in a target dynamic library, and the reading priority of the target dynamic library is higher than that of the original dynamic library.
[0165] The identification module 920 is used to identify the target deletion method of the target data during the process of calling the target deletion function.
[0166] The protection deletion module 930 is used to execute the protection deletion operation on the target data if the target deletion mode is the protection deletion based on the recycling bin mechanism.
[0167] The direct deletion module 940 is used to call the original deletion function to directly delete the target data if the target deletion mode is direct deletion.
[0168] In one embodiment, the loading module is also used to obtain a newly added dynamic library, which includes a target deletion function; compile the newly added dynamic library through a compiler to obtain a target dynamic library; write the target dynamic library into a preload file of the linker, and the reading priority of the preload file is higher than other loading directories of the linker.
[0169] In one embodiment, the loading module is further used to read the target dynamic library according to the preload file; and read and call the target deletion function in the target dynamic library.
[0170] In one embodiment, the identification module is also used to read configuration information corresponding to the deletion method from the configuration file, and the configuration information includes a specified flag bit, which is used to indicate whether the recycle bin mechanism is globally enabled; if the specified flag bit indicates that the recycle bin mechanism is globally enabled, then the target deletion method of the target data is determined to be protective deletion based on the recycle bin mechanism.
[0171] In one embodiment, the configuration information also includes at least one protection directory for which a recycle bin mechanism needs to be enabled, and the identification module is also used to match the target data with any protection directory to obtain a matching result if a specified flag indicates that the recycle bin mechanism is not enabled globally; if the matching result indicates that there is a protection directory that matches the target data, then the target deletion method of the target data is determined to be protection deletion based on the recycle bin mechanism; if the matching result indicates that there is no protection directory that matches the target data, then the target deletion method of the target data is determined to be direct deletion.
[0172] In one embodiment, the protection deletion module is also used to back up the target data based on a preset recycle bin directory; if the target data is successfully backed up, the original deletion function is called in the original directory of the target data to perform a direct deletion operation on the target data.
[0173] In one embodiment, the protection deletion module is also used to save the attribute information of the target data; to pack and compress the target data through a compression command to obtain a compressed package of the target data; and to store the compressed package in a preset recycle bin directory.
[0174] In one embodiment, the protection deletion module is also used to obtain a compressed package of the data to be recovered based on the identifier of the data to be recovered if a recovery command for any data to be recovered in the recycle bin directory is received; and decompress the compressed package to obtain the data to be recovered.
[0175] In one embodiment, the identification module is also used to obtain the triggering method of the deletion command; if the triggering method is consistent with the preset triggering method, the configuration information corresponding to the deletion method is read from the configuration file, and based on the configuration information, the target deletion method of the target data is identified; if the triggering method is inconsistent with the preset triggering method, the original deletion function is called to perform the data deletion operation.
[0176] In application, each module in the data deletion device may be a software program module, or may be implemented by different logic circuits integrated in a processor, or may be implemented by multiple distributed processors.
[0177] Fig.12 A schematic diagram of the structure of a computer device for implementing a data deletion method provided in an embodiment of the present application. Fig.12 As shown, the computer device 1000 of this embodiment includes: at least one processor 1010 ( Fig.12 Only one is shown in the figure) a processor, a memory 1020, and a computer program 1030 stored in the memory 1020 and executable on the at least one processor 1010, and when the processor 1010 executes the computer program 1030, the steps in any of the above-mentioned robot control method embodiments are implemented.
[0178] The computer device 1000 may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The computer device 1000 may include, but is not limited to, a processor 1010 and a memory 1020. Those skilled in the art will appreciate that Fig.12 The computer device 1000 is merely an example and does not constitute a limitation on the computer device 1000 . The computer device 1000 may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the computer device 1000 may also include input and output devices, network access devices, etc.
[0179] The processor 1010 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.
[0180] In some embodiments, the memory 1020 may be an internal storage unit of the computer device 1000, such as a hard disk or memory of the computer device 1000. In other embodiments, the memory 1020 may also be an external storage device of the computer device 1000, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the computer device 1000. Further, the memory 1020 may also include both an internal storage unit of the computer device 1000 and an external storage device. The memory 1020 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program, etc. The memory 1020 may also be used to temporarily store data that has been output or is to be output.
[0181] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.
[0182] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0183] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.
[0184] An embodiment of the present application provides a computer program product. When the computer program product runs on a mobile terminal, the mobile terminal can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0185] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the device / terminal device, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electric carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0186] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0187] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0188] In the embodiments provided in the present application, it should be understood that the disclosed devices / network equipment and methods can be implemented in other ways. For example, the device / network equipment embodiments described above are merely schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0189] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0190] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.
Claims
1. A data deletion method, characterized in that: The method comprises: In response to a delete command for target data, a target delete function is called, wherein the target delete function is contained in a target dynamic library, and the read priority of the target dynamic library is higher than that of the original dynamic library; In the process of calling the target deletion function, identifying the target deletion mode of the target data; If the target deletion method is a protection deletion based on a recycle bin mechanism, then a protection deletion operation is performed on the target data; If the target deletion method is direct deletion, the original deletion function is called to directly delete the target data, and the original deletion function is included in the original dynamic library.
2. The data deletion method according to claim 1, characterized in that: Before calling the target deletion function, the method further includes: Acquire a newly added dynamic library, wherein the newly added dynamic library includes the target deletion function; Compiling the newly added dynamic library through a compiler to obtain the target dynamic library; The target dynamic library is written into a preload file of the linker, and the reading priority of the preload file is higher than other loading directories of the linker.
3. The data deletion method according to claim 2, characterized in that: The calling target deletion function includes: Reading the target dynamic library according to the preload file; In the target dynamic library, the target deletion function is read and called.
4. The data deletion method according to claim 1, wherein: In the process of calling the target deletion function, identifying the target deletion method of the target data includes: Reading configuration information corresponding to the deletion mode from the configuration file, the configuration information including a specified flag bit, the specified flag bit being used to indicate whether a recycle bin mechanism is globally enabled; If the designated flag indicates that the recycle bin mechanism is globally enabled, then the target deletion method of the target data is determined to be protective deletion based on the recycle bin mechanism.
5. The data deletion method according to claim 4, characterized in that: The configuration information also includes at least one protection directory for which a recycle bin mechanism needs to be enabled, and the method further includes: If the specified flag indicates that the recycle bin mechanism is not enabled globally, matching the target data with any of the protection directories to obtain a matching result; If the matching result indicates that there is a protection directory that matches the target data, determining that the target deletion method of the target data is a protection deletion based on a recycle bin mechanism; If the matching result indicates that there is no protection directory matching the target data, it is determined that the target deletion method of the target data is direct deletion.
6. The data deletion method according to any one of claims 1 to 5, characterized in that: The performing of the protection deletion operation on the target data includes: Backing up the target data based on a preset recycle bin directory; If the target data is backed up successfully, then in the original directory of the target data, the original deletion function is called to perform a direct deletion operation on the target data.
7. The data deletion method according to claim 6, characterized in that: The backing up of the target data based on the preset recycle bin directory includes: Saving attribute information of the target data; Packing and compressing the target data through a compression command to obtain a compressed package of the target data; The compressed package is stored in a preset recycle bin directory.
8. The data deletion method according to claim 7, characterized in that: The method further comprises: If a recovery command for any data to be recovered in the recycle bin directory is received, a compressed package of the data to be recovered is obtained based on the identifier of the data to be recovered; The compressed package is decompressed to obtain the data to be restored.
9. The data deletion method according to any one of claims 4 or 5, characterized in that: Before reading the configuration information corresponding to the deletion mode from the configuration file, the method further includes: Obtaining a triggering method for the deletion command; If the trigger mode is consistent with the preset trigger mode, reading configuration information corresponding to the deletion mode from the configuration file, and identifying the target deletion mode of the target data based on the configuration information; If the trigger mode is inconsistent with the preset trigger mode, the original deletion function is called to perform the data deletion operation.
10. A computing device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 9 is implemented.
Citation Information
Patent Citations
File delete method and file open method
CN101000614A
Application method and system of recycle bin of distributed cluster
CN107239521A
Recycle bin system and file recycling method
CN110888847A
Resource deletion method and device, electronic equipment and storage medium
CN113986138A
Program protection method, device and equipment and computer readable storage medium
CN118013511A