File processing method and device

Through the global hash index directory and hard link technology, the complex problems of file comparison and deduplication in the existing technology are solved, and the efficient use of disk space is achieved.

CN120255819BActive Publication Date: 2025-09-30BEIJING HAIYUDONGXIANG TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510668508.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-05-23
Publication Date
2025-09-30
Estimated Expiration
2045-05-23

AI Technical Summary

Technical Problem

Existing technologies rely on databases during file comparison and deduplication, which is complex and not simple enough to implement, resulting in a waste of disk space.

Method used

A global hash index directory is used instead of the database. The existence of identical files is determined by calculating the file hash value, and hard links are used to share disk space to achieve file deduplication and file sharing during upload.

Benefits of technology

It simplifies the file handling process, saves disk space, and is simpler to implement, avoiding the complexity of the database.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120255819B_ABST
    Figure CN120255819B_ABST
Patent Text Reader

Abstract

The present application provides a method and device for file processing, the method comprising: calculating a hash value corresponding to a first file, determining whether a second file exists in a pre-created first global hash index directory based on the hash value corresponding to the first file, and if the second file exists in the first global hash index directory, replacing the first file with a hard link to the second file; and / or when a third file is uploaded, obtaining a hash value corresponding to the third file, determining whether a fourth file exists in a pre-created second global hash index directory based on the hash value corresponding to the third file, and if the fourth file exists in the second global hash index directory, creating the third file and hard linking the third file to the fourth file, which can save disk space and is simpler to implement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and in particular to a method and device for file processing. Background Art

[0002] To save disk space, file comparison and deduplication are required in many scenarios. For example, deduplication is required between different versions of game data files (shared by all users) stored on a cloud storage server, so that only one copy of the game data file is retained on the cloud storage server. Another example is that before uploading a version of a game data file (shared by all users) to the cloud storage server, the cloud storage server is checked to see if there are files with the same content. If so, the game data file is not uploaded to the cloud storage server. Otherwise, the game data file is uploaded to the cloud storage server, so that only one copy of the game data file is retained on the cloud storage server. Existing solutions for these scenarios often use a database to store the MD5 values ​​of the files. File comparison is then performed based on the MD5 values ​​stored in the database. Based on the comparison results, if the MD5 values ​​of different files are the same, hard links are used to make the different files share the same disk data. Because existing solutions rely on databases, implementation is complex. Furthermore, when a file needs to be deleted, the database must be notified to delete the corresponding data record, which complicates the overall implementation of existing solutions.

[0003] Therefore, how to provide an optimized file processing solution that can save disk space and is simpler to implement has become a technical problem that needs to be solved urgently. Summary of the Invention

[0004] In order to solve the technical problems existing in the prior art, the embodiments of the present application provide a method and device for file processing.

[0005] In a first aspect, an embodiment of the present application provides a method for file processing, comprising:

[0006] Calculating a hash value corresponding to the first file, determining whether a second file exists in a pre-created first global hash index directory based on the hash value corresponding to the first file, and if the second file exists in the first global hash index directory, replacing the first file with a hard link to the second file, wherein the relative path of the second file relative to the first global hash index directory contains the hash value corresponding to the first file; and / or

[0007] When the third file is uploaded, the hash value corresponding to the third file is obtained, and whether the fourth file exists in the pre-created second global hash index directory is determined based on the hash value corresponding to the third file. If the fourth file exists in the second global hash index directory, the third file is created and hard-linked to the fourth file, wherein the relative path of the fourth file relative to the second global hash index directory contains the hash value corresponding to the third file.

[0008] In a second aspect, an embodiment of the present application further provides a file processing device, comprising:

[0009] A processing unit is used to calculate a hash value corresponding to a first file, determine whether a second file exists in a pre-created first global hash index directory based on the hash value corresponding to the first file, and if the second file exists in the first global hash index directory, replace the first file with a hard link to the second file, wherein the relative path of the second file relative to the first global hash index directory contains the hash value corresponding to the first file; and / or when a third file is uploaded, obtain a hash value corresponding to the third file, determine whether a fourth file exists in a pre-created second global hash index directory based on the hash value corresponding to the third file, and if the fourth file exists in the second global hash index directory, create the third file and hard link the third file to the fourth file, wherein the relative path of the fourth file relative to the second global hash index directory contains the hash value corresponding to the third file.

[0010] In summary, the file processing method and device provided in the embodiments of the present application do not use a database, but rely on a pre-created global hash index directory (i.e., a first global hash index directory and / or a second global hash index directory): when performing file deduplication, it is determined whether the second file exists in the first global hash index directory. If the second file exists in the first global hash index directory, it means that there is a file with the same content as the first file, and the first file is replaced with a hard link to the second file, so that the first file and the second file share a copy of disk data; and when uploading a new file (i.e., a third file), it is determined whether the fourth file exists in the second global hash index directory. If the fourth file exists in the second global hash index directory, it means that there is a file with the same content as the third file, and the third file is no longer uploaded, but a third file is created and hard-linked to the fourth file, so that the third file and the fourth file share a copy of disk data. This can save disk space, and since no database is used, it is simpler to implement than the existing solution. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 A flowchart of an embodiment of a method for file processing provided in an embodiment of the present application;

[0012] Figure 2A structural diagram of an embodiment of a file processing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0013] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the drawings in the present application only serve the purpose of illustration and description and are not used to limit the scope of protection of the present application. In addition, it should be understood that the schematic drawings are not drawn to scale. The flowcharts used in this application illustrate the operations implemented according to some embodiments of the present application. It should be understood that the operations of the flowcharts can be implemented out of sequence, and steps without logical context can be reversed or implemented simultaneously. In addition, those skilled in the art, under the guidance of the contents of this application, can add one or more other operations to the flowchart, or remove one or more operations from the flowchart.

[0014] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present application.

[0015] It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the existence of the features declared thereafter, but does not exclude the addition of other features.

[0016] Reference Figure 1 As shown, an embodiment of the present application provides a flowchart of a method for file processing, the method comprising:

[0017] S10. Calculate a hash value corresponding to the first file, and determine whether a second file exists in a pre-created first global hash index directory based on the hash value corresponding to the first file; if the second file exists in the first global hash index directory, replace the first file with a hard link to the second file, wherein the relative path of the second file relative to the first global hash index directory contains the hash value corresponding to the first file; and / or

[0018] S11. When the third file is uploaded, obtain the hash value corresponding to the third file, and determine whether there is a fourth file in the pre-created second global hash index directory based on the hash value corresponding to the third file. If the fourth file exists in the second global hash index directory, create the third file and hard link the third file to the fourth file, wherein the relative path of the fourth file relative to the second global hash index directory contains the hash value corresponding to the third file.

[0019] In this embodiment, it should be noted that step S10 is aimed at the scenario of file deduplication. For example, if it is necessary to dedupe files in at least one directory (for example, the at least one directory is a file directory shared by all users in the cloud storage server, and the at least one directory stores game resources, SO libraries and other files shared by all users), then step S10 can be executed for each file in the at least one directory. In step S10, if the second file exists in the first global hash index directory, the first file is replaced with a hard link to the second file. Otherwise, if the second file does not exist in the first global hash index directory, the second file is created in the first global hash index directory and hard-linked to the first file. The relative path of the second file relative to the first global hash index directory contains the hash value corresponding to the first file. For example, suppose you need to deduplicate the files in the directory / game_resources. There are five files in the directory / game_resources: / game_resources / 1.txt, / game_resources / 2.txt, / game_resources / 3.txt, / game_resources / 4.txt, and / game_resources / 5.txt. Then you can create the first global hash index directory / global_hash_index_dir. Assume that the hash values ​​of 1.txt, 2.txt, 3.txt, 4.txt, and 5.txt are AAAAAAAA, BBBBBBBB, CC respectively. CCCCCC, AAAAAAAA and BBBBBBBB, for 1.txt, since there is no file named AAAAAAAA in / global_hash_index_dir, it is necessary to create the file / global_hash_index_dir / AAAAAAAA and hard link / global_hash_index_dir / AAAAAAAA to / game_resources / 1.txt. At this time, / game_resources / 1.txt and / global_hash_index_dir / AAAAAAAA share the same disk data (that is, the disk data of / game_resources / 1.txt).Similarly, for 2.txt, you need to create the file / global_hash_index_dir / BBBBBBBB and hard link / global_hash_index_dir / BBBBBBBB to / game_resources / 2.txt. At this time, / game_resources / 2.txt and / global_hash_index_dir / BBBBBBBB share the same disk data; for 3.txt, you need to create the file / global_hash_index_dir / CCCCCCCC and hard link / global_hash_index_dir / CCCCCCCC to / game_resources / 3.txt. At this time, / game_resources / 3.txt and / global_hash_index_dir / CCCCCCCC share the same disk data. For 4.txt, since there is a file / global_hash_index_dir / AAAAAAAA, you need to replace / game_resources / 4.txt with a hard link to / global_hash_index_dir / AAAAAAAA. At this time, / game_resources / 1.txt, / global_hash_index_dir / AAAAAAAA, and / game_resources / 4.txt share the same disk data. For 5.txt, since there is a file / global_hash_index_dir / BBBBBBBB, you need to replace / game_resources / 5.txt with a hard link to / global_hash_index_dir / BBBBBBBB. At this time, / game_resources / 2.txt, / global_hash_index_dir / BBBBBBBB, and / game_resources / 5.txt share the same disk data. In this example, the hash value corresponding to the first file is the hash value of the first file. For example, the relative path of the second file / global_hash_index_dir / AAAAAAAA relative to the first global hash index directory / global_hash_index_dir is AAAAAAAA (i.e., the hash value of the first file / game_resources / 1.txt). The hash value corresponding to the first file may include the hash value of all contents of the first file, the hash value of the first data, the hash value of a portion of the first file, or the hash value of the second data. The first data may include the hash value of all contents of the first file, and the second data may include the hash value of a portion of the first file.In addition to the hash value of all the contents of the first file, the hash value corresponding to the first file may also include the hash value of at least one basic attribute of the first file and / or the extended attribute of the first file. The basic attributes of the first file include the access permission mode of the first file, the owner user of the first file, the user group group to which the first file belongs, and the last modification time of the first file. For example, the hash value of all the contents of the first file 6.txt is DDDDDDDD, the access permission mode of 6.txt is 123, the owner user of 6.txt is 10000, the user group group to which 6.txt belongs is 10000, and the first global hash index directory is / g global_hash_index_dir, the path of the second file corresponding to 6.txt can be / global_hash_index_dir / DDDDDDDD or / global_hash_index_dir / DDDDDDDD_123_10000_10000 (the symbol "_" in / global_hash_index_dir / DDDDDDDD_123_10000_10000 can be replaced by other separators) or / global_hash_index_dir / DDDDDDDD / 123_10000_10000, etc. In addition to the hash value of all the contents of the first file, the first data may also include the hash value of at least one basic attribute of the first file and / or the extended attribute of the first file. For example, assuming that the hash value of all extended attributes of the first file 6.txt is EEEEE, the first data corresponding to the first file 6.txt may include DDDDDDDD, 123, 10000, 10000 and EEEEE, and the path of the second file corresponding to 6.txt may be / global_hash_index_dir / FFFFFFFF, where FFFFFFFF is the hash value of the first data.The hash value corresponding to the first file may include a hash value of part of the content of the first file. For example, at least one part of the content is extracted from the first file, and a hash value is calculated for each extracted part to obtain at least one hash value. The hash value of the part of the content of the first file includes the at least one hash value. In addition, the hash value corresponding to the first file may also include a hash value of all the contents of the first file and / or a hash value of at least one basic attribute of the first file and / or an extended attribute of the first file. For example, the first file 6.txt is divided into two parts according to a size of 1M, and the hash value of the first part is MMMMM, and the hash value of the second part is NNNNN. The path of the second file corresponding to 6.txt can be / global_hash_index_dir / MMMMM / NNNNN or / global_hash_index_dir / MMMMM / NNNNN_123_10000_10000 or / global_hash_index_dir / MMMMM / NNNNN / 123_10000_10000, etc. In addition to including the hash value of part of the contents of the first file, the second data may also include the hash value of all the contents of the first file and / or the hash value of at least one basic attribute of the first file and / or the hash value of an extended attribute of the first file. For example, the second data corresponding to 6.txt may include MMMMM, NNNNN, and EEEEE, and the path of the second file corresponding to 6.txt may be / global_hash_index_dir / GGGGGGGG, where GGGGGGGG is the hash value of the second data. By calculating the hash value of part of the contents of the first file and using the hash value of part of the contents of the first file in the judgment logic, the operation efficiency can be improved.

[0020] Step S11 is for the scenario of uploading files, such as the need to upload a file in one device to another device (such as uploading a new version of a game data file to a cloud storage server, which stores an old version of a game data file). In this scenario, step S11 can be applied to the other device. Obtaining the hash value corresponding to the third file in step S11 may include receiving the hash value corresponding to the third file uploaded by other devices, or receiving the content of the third file uploaded by other devices, and calculating the hash value corresponding to the third file based on the content of the third file. The hash value corresponding to the third file may include the hash value of all the contents of the third file, or the hash value of the third data, or the hash value of part of the contents of the third file, or the hash value of the fourth data, wherein the third data includes the hash value of all the contents of the third file, and the fourth data includes the hash value of part of the contents of the third file. The judgment logic in step S11 is consistent with the judgment logic in step S10 and will not be repeated here. If the fourth file exists in the second global hash index directory, it is necessary to determine the absolute path of the third file based on the relative path of the third file uploaded by another device (this is prior art and will not be described here in detail). Then, a third file is created based on the absolute path of the third file and hard-linked to the fourth file so that the third and fourth files share the same disk data (i.e., the disk data of the fourth file). The second global hash index directory may be the same as or different from the first global hash index directory.For example, assuming that the third file 7.txt needs to be uploaded to the device applied in step S11, the hash value, access permission mode, owner user and user group group of 7.txt are BBBBBBBB, 336, 11000 and 11000 respectively, and the second global hash index directory / global_hash_index_dir contains / global_hash_index_dir / AAAAAAAA_220_10000_10000, / global_hash_index_dir / BBBBBBBB_336_11000_11000, / global_hash_index_dir / CCCCCCCC_440_12000_12000 and / global_hash_index_dir / BBBBBBBB_461_1 If there are four files in the second global hash index directory (i.e., the file path in the second global hash index directory is in the form of / global_hash_index_dir / hash value_access permission mode_owner user_user group group), then since there is a fourth file / global_hash_index_dir / BBBBBBBB_336_11000_11000 corresponding to 7.txt, 7.txt is not uploaded to the device used in step S11. Instead, 7.txt is created and hard-linked to / global_hash_index_dir / BBBBBBBB_336_11000_11000, so that 7.txt and / global_hash_index_dir / BBBBBBBB_336_11000_11000 share the same disk data. If the fourth file does not exist in the second global hash index directory, the third file is received and stored, a fourth file is created in the second global hash index directory, and the fourth file is hard-linked to the third file.For example, assuming that the third file 8.txt needs to be uploaded to the device applied in step S11, the hash value, access permission mode, owner user and user group group of 8.txt are BBBBBBBB, 425, 14000 and 14000 respectively, and the second global hash index directory / global_hash_index_dir contains / global_hash_index_dir / AAAAAAAA_256_10000_10000, / global_hash_index_dir / BBBBBBBB_312_11000_11000, / global_hash_index_dir / CCCCCCCC_370_12000_12000 and / global_hash_index_dir / AAAAAAAA_256_10000_10000 There are 4 files in r / BBBBBBBB_425_13000_13000. Since there is no file named BBBBBBBB_425_14000_14000 under / global_hash_index_dir, it is necessary to upload 8.txt to the device applied in step S11, store 8.txt, create / global_hash_index_dir / BBBBBBBB_425_14000_14000, and hard link / global_hash_index_dir / BBBBBBBB_425_14000_14000 to 8.txt, so that / global_hash_index_dir / BBBBBBBB_425_14000_14000 and 8.txt share the same disk data.

[0021] The file processing method provided in the embodiment of the present application does not use a database, but instead relies on a pre-created global hash index directory (i.e., a first global hash index directory and / or a second global hash index directory): when performing file deduplication, it is determined whether the second file exists in the first global hash index directory. If the second file exists in the first global hash index directory, it indicates that there is a file with the same content as the first file, and the first file is replaced with a hard link to the second file, so that the first file and the second file share a copy of disk data; and when uploading a new file (i.e., a third file), it is determined whether the fourth file exists in the second global hash index directory. If the fourth file exists in the second global hash index directory, it indicates that there is a file with the same content as the third file, and the third file is no longer uploaded. Instead, the third file is created and hard-linked to the fourth file, so that the third file and the fourth file share a copy of disk data. This can save disk space, and since no database is used, the implementation is simpler than the existing solution.

[0022] Based on the above method embodiment, the method may further include:

[0023] Delete the file whose nlink attribute is 1 in the index node inode pointed to by the directory entry dentry in the first global hash index directory and / or the second global hash index directory; or

[0024] Delete files whose nlink attribute in the index node inode pointed to by the directory entry dentry in the first global hash index directory and / or the second global hash index directory is 1 and whose time interval between the ctime attribute and the current time is greater than a preset threshold.

[0025] In this embodiment, it should be noted that for a certain file in the first global hash index directory, if the nlink attribute in the index node inode pointed to by the directory entry dentry of the file is 1, it means that except for the file, there are no other files whose directory entry dentry points to the index node inode, and the file needs to be deleted. In order to prevent the content of the file from being used within a short period of time after the file is deleted, an additional condition can be added on the basis of the nlink attribute in the index node inode pointed to by the directory entry dentry being 1: the time interval between the ctime attribute in the index node inode pointed to by the directory entry dentry and the current time is greater than a preset threshold (for example, 24 hours). If there are files that meet these two conditions in the first global hash index directory, the files that meet these two conditions in the first global hash index directory can be deleted. The processing logic for deleting files in the second global hash index directory is the same as the processing logic for deleting files in the first global hash index directory, and will not be repeated here.

[0026] Reference Figure 2 FIG. 1 is a schematic diagram of a file processing device provided in an embodiment of the present application, the device comprising:

[0027] The processing unit 20 is used to calculate the hash value corresponding to the first file, and determine whether the second file exists in the pre-created first global hash index directory based on the hash value corresponding to the first file; if the second file exists in the first global hash index directory, the first file is replaced with a hard link to the second file, wherein the relative path of the second file relative to the first global hash index directory contains the hash value corresponding to the first file; and / or when the third file is uploaded, obtain the hash value corresponding to the third file, and determine whether the fourth file exists in the pre-created second global hash index directory based on the hash value corresponding to the third file; if the fourth file exists in the second global hash index directory, create the third file and hard link the third file to the fourth file, wherein the relative path of the fourth file relative to the second global hash index directory contains the hash value corresponding to the third file.

[0028] The file processing device provided in the embodiment of the present application does not use a database, but relies on a pre-created global hash index directory (i.e., a first global hash index directory and / or a second global hash index directory): when performing file deduplication, it is determined whether the second file exists in the first global hash index directory. If the second file exists in the first global hash index directory, it means that there is a file with the same content as the first file, and the first file is replaced with a hard link to the second file, so that the first file and the second file share a copy of disk data; and when uploading a new file (i.e., a third file), it is determined whether the fourth file exists in the second global hash index directory. If the fourth file exists in the second global hash index directory, it means that there is a file with the same content as the third file, and the third file is no longer uploaded, but a third file is created and hard-linked to the fourth file, so that the third file and the fourth file share a copy of disk data. This can save disk space, and because no database is used, the implementation is simpler than the existing solution.

[0029] Based on the aforementioned device embodiment, the hash value corresponding to the first file may include a hash value of all contents of the first file, or a hash value of the first data, or a hash value of a portion of the contents of the first file, or a hash value of the second data, wherein the first data includes the hash value of all contents of the first file, and the second data includes the hash value of the portion of the contents of the first file;

[0030] The hash value corresponding to the third file may include the hash value of all contents of the third file or the hash value of the third data or the hash value of part of the contents of the third file or the hash value of the fourth data, wherein the third data includes the hash value of all contents of the third file and the fourth data includes the hash value of part of the contents of the third file.

[0031] Based on the aforementioned device embodiment, the processing unit may also be used for:

[0032] If the second file does not exist in the first global hash index directory, the second file is created in the first global hash index directory and the second file is hard-linked to the first file.

[0033] Based on the aforementioned device embodiment, the processing unit may also be used for:

[0034] If the fourth file does not exist in the second global hash index directory, the third file is received and stored, a fourth file is created in the second global hash index directory, and the fourth file is hard-linked to the third file.

[0035] Based on the above device embodiment, the device may further include:

[0036] A deletion unit is used to delete files whose nlink attribute is 1 in the index node inode pointed to by the directory entry dentry in the first global hash index directory and / or the second global hash index directory; or delete files whose nlink attribute is 1 in the index node inode pointed to by the directory entry dentry in the first global hash index directory and / or the second global hash index directory and whose time interval between the ctime attribute and the current time is greater than a preset threshold.

[0037] The file processing device provided in the embodiment of the present application has an implementation process consistent with the file processing method provided in the embodiment of the present application, and the effect that can be achieved is also the same as the file processing method provided in the embodiment of the present application, which will not be repeated here.

[0038] The above are only specific embodiments of the present application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.

Claims

1. A method for file processing, characterized in that: include: Calculating a hash value corresponding to the first file, determining whether a second file exists in a pre-created first global hash index directory based on the hash value corresponding to the first file, and if the second file exists in the first global hash index directory, replacing the first file with a hard link to the second file, wherein the relative path of the second file relative to the first global hash index directory contains the hash value corresponding to the first file; and / or When the third file is uploaded, the hash value corresponding to the third file is obtained, and whether the fourth file exists in the pre-created second global hash index directory is determined based on the hash value corresponding to the third file. If the fourth file exists in the second global hash index directory, the third file is created and hard-linked to the fourth file, wherein the relative path of the fourth file relative to the second global hash index directory contains the hash value corresponding to the third file.

2. The method according to claim 1, wherein The hash value corresponding to the first file includes a hash value of all contents of the first file, or a hash value of first data, or a hash value of part of the contents of the first file, or a hash value of second data, wherein the first data includes a hash value of all contents of the first file, and the second data includes a hash value of part of the contents of the first file; The hash value corresponding to the third file includes the hash value of all contents of the third file or the hash value of the third data or the hash value of part of the contents of the third file or the hash value of the fourth data, wherein the third data includes the hash value of all contents of the third file and the fourth data includes the hash value of part of the contents of the third file.

3. The method according to claim 1, wherein Also includes: If the second file does not exist in the first global hash index directory, the second file is created in the first global hash index directory and the second file is hard-linked to the first file.

4. The method according to claim 1, wherein Also includes: If the fourth file does not exist in the second global hash index directory, the third file is received and stored, a fourth file is created in the second global hash index directory, and the fourth file is hard-linked to the third file.

5. The method according to any one of claims 1 to 4, characterized in that Also includes: Delete the file whose nlink attribute is 1 in the index node inode pointed to by the directory entry dentry in the first global hash index directory and / or the second global hash index directory; or Delete files whose nlink attribute in the index node inode pointed to by the directory entry dentry in the first global hash index directory and / or the second global hash index directory is 1 and whose time interval between the ctime attribute and the current time is greater than a preset threshold.

6. A file processing device, characterized in that: include: A processing unit is used to calculate a hash value corresponding to a first file, determine whether a second file exists in a pre-created first global hash index directory based on the hash value corresponding to the first file, and if the second file exists in the first global hash index directory, replace the first file with a hard link to the second file, wherein the relative path of the second file relative to the first global hash index directory contains the hash value corresponding to the first file; and / or when a third file is uploaded, obtain a hash value corresponding to the third file, determine whether a fourth file exists in a pre-created second global hash index directory based on the hash value corresponding to the third file, and if the fourth file exists in the second global hash index directory, create the third file and hard link the third file to the fourth file, wherein the relative path of the fourth file relative to the second global hash index directory contains the hash value corresponding to the third file.

7. The device according to claim 6, characterized in that The hash value corresponding to the first file includes a hash value of all contents of the first file, or a hash value of first data, or a hash value of part of the contents of the first file, or a hash value of second data, wherein the first data includes a hash value of all contents of the first file, and the second data includes a hash value of part of the contents of the first file; The hash value corresponding to the third file includes the hash value of all contents of the third file or the hash value of the third data or the hash value of part of the contents of the third file or the hash value of the fourth data, wherein the third data includes the hash value of all contents of the third file and the fourth data includes the hash value of part of the contents of the third file.

8. The device according to claim 6, wherein The processing unit is further configured to: If the second file does not exist in the first global hash index directory, the second file is created in the first global hash index directory and the second file is hard-linked to the first file.

9. The device according to claim 6, wherein The processing unit is further configured to: If the fourth file does not exist in the second global hash index directory, the third file is received and stored, a fourth file is created in the second global hash index directory, and the fourth file is hard-linked to the third file.

10. The device according to any one of claims 6 to 9, characterized in that Also includes: A deletion unit is used to delete files whose nlink attribute is 1 in the index node inode pointed to by the directory entry dentry in the first global hash index directory and / or the second global hash index directory; or delete files whose nlink attribute is 1 in the index node inode pointed to by the directory entry dentry in the first global hash index directory and / or the second global hash index directory and whose time interval between the ctime attribute and the current time is greater than a preset threshold.

Citation Information

Patent Citations

  • File system duplicate removal method and device based on cloud storage

    CN103136243A

  • File redundancy removal method for terminal equipment, terminal equipment and storage medium

    CN114860677A