A file scanning method and related device

By comparing the directory modification timestamps of the storage device, the dirty directory collection is generated, and only dirty directories and their subfiles are traversed and parsed, which solves the problem of long and low efficiency of file scanning time when storage devices frequently connect to electronic devices, and improves scanning efficiency and user experience.

CN114116611BActive Publication Date: 2025-08-22HUAWEI TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202010890951.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-29
Publication Date
2025-08-22
Estimated Expiration
2040-08-29

AI Technical Summary

Technical Problem

When the storage device frequently connects to the electronic device, the file scanning time in the prior art is long and the efficiency is low, resulting in poor user experience.

Method used

By comparing the last and current directory modification timestamps of the storage device, a dirty directory collection is generated, and only dirty directories and their subfiles are traversed and parsed, avoiding full disk traversal and shortening scanning time.

Benefits of technology

Improve file scanning efficiency, reduce user waiting time, and improve user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114116611B_ABST
    Figure CN114116611B_ABST
Patent Text Reader

Abstract

An embodiment of the present invention discloses a file scanning method and related apparatus. The method may include: receiving a scan request for a target storage device and obtaining first file information; the first file information includes first directory information of a scanned file list of the target storage device, the directory information including a first modification timestamp for each directory in the scanned file list; obtaining second file information, the second file information including second directory information of a to-be-scanned file list of the target storage device, the directory information including a second modification timestamp for each directory in the to-be-scanned file list; comparing the first directory information with the second directory information to generate a dirty directory set; a dirty directory is a directory whose first modification timestamp is inconsistent with the second modification timestamp or appears in the second directory information but not in the first directory information. The embodiment of the present invention can improve file scanning efficiency when a storage device is connected to an electronic device and the electronic device performs a file scan.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of document scanning, and in particular to a document scanning method and related devices. Background Art

[0002] With the development of electronic devices, the application scenarios of electronic devices such as smart screens, personal computers, and tablets are becoming more and more diverse. When a storage device (such as a mobile hard drive or USB flash drive) is connected to an electronic device, the electronic device can obtain file information of all storage devices by scanning the files in the storage device. Currently, as the storage capacity of storage devices continues to expand, the number of files that can be stored increases, which increases the number of files that need to be traversed during the file scanning process.

[0003] For example, a user wants to view the media information in a storage device. When the storage device is connected to an electronic device, the electronic device scans the storage device for media files. The scanning process includes traversing all files to be scanned in the storage device. After a media file is found, the media file will be parsed accordingly to obtain the file scanning results (such as thumbnails of media files, etc.) and store them in the media database. Ultimately, the electronic device can obtain the media file information in the storage device by reading the data in the media database. When the storage device is removed from the electronic device, the electronic device will clear the scan results of the storage device temporarily stored in the media database. Therefore, when the storage device is connected to the electronic device again, the electronic device will re-scan the entire storage device.

[0004] However, in scenarios where storage devices such as smart screens are frequently plugged in and out, if there are a large number of files on the storage device, each full disk scan will take a lot of time, resulting in users being unable to view file contents immediately, thereby reducing the user experience.

[0005] Therefore, how to improve the file scanning efficiency when the storage device is connected to the electronic device and the electronic device performs file scanning is an issue that needs to be solved urgently. Summary of the Invention

[0006] The technical problem to be solved by the embodiments of the present invention is to provide a file scanning method and related devices, which solve the problem of long file scanning time and low efficiency when the same storage device is frequently connected to the same electronic device.

[0007] In a first aspect, an embodiment of the present invention provides a file scanning method, which may include:

[0008] Receive a scan request for a target storage device and obtain first file information; the first file information includes first directory information of a scanned file list stored by the target storage device, and the first directory information includes a first modification timestamp of each directory in the scanned file list; obtain second file information, the second file information includes second directory information of a to-be-scanned file list stored by the target storage device, and the second directory information includes a second modification timestamp of each directory in the to-be-scanned file list; compare the first directory information with the second directory information to generate a dirty directory set; the dirty directories in the dirty directory set are directories whose file names are the same in the first directory information and the second directory information and whose first modification timestamp is inconsistent with the second modification timestamp, or directories that appear in the second directory information but do not appear in the first directory information. In an embodiment of the present invention, when the same storage device is connected to an electronic device multiple times, the electronic device can determine that the two directories with inconsistent modification timestamps are dirty directories by comparing the modification timestamp of the last directory of the storage device with the modification timestamp of the current latest directory, and traverse the subfiles and subdirectories under the determined dirty directory, so as to further determine the specific files or directories that have been changed, avoid traversing the entire disk of the storage device, reduce the number of traversed files, shorten the time spent on traversal, and improve file scanning efficiency.

[0009] In one possible implementation, the obtaining of the first file information includes searching for the first file information that matches the universal unique identifier (UUID) of the storage device based on the UUID. In an embodiment of the present invention, since a UUID is set for each storage device, and the UUID corresponding to each storage device is different, when the storage device is connected to the electronic device again, the electronic device will search the database for the latest scan result of the corresponding storage device based on this UUID. By implementing the method of an embodiment of the present invention, the electronic device can find the latest scan result of the storage device more quickly when the storage device is connected again without additionally marking the scan result of the storage device.

[0010] In one possible implementation, generating a dirty directory set includes, when no directory exists in the first directory information, adding the root directory of the list of files to be scanned stored in the storage device to the dirty directory set. In an embodiment of the present invention, when a storage device is connected to an electronic device for the first time, there is no record of the scanning results of the storage device in the database of the electronic device. In this case, initially, only the root directory of the files stored in the storage device is recorded as a dirty directory. The root directory is then traversed, and if a new directory or a new dirty directory is found during the traversal process, the new directory or the new dirty directory is added to the dirty directory set. By implementing the method of the embodiment of the present invention, the first file scan of the storage device can be completed quickly.

[0011] In a possible implementation, after comparing the first directory information with the second directory information, the method further includes deleting the directory to be deleted from the first directory information and deleting the scan result corresponding to the directory to be deleted; the directory to be deleted is a directory that appears in the first directory information and does not appear in the second directory information. In an embodiment of the present invention, after the storage device is unplugged, if the user deletes some directories stored in the storage device, when the electronic device is connected again, these deleted directories will not have the latest modification timestamp, but the database of the electronic device will have the last modification timestamp of these directories. When the electronic device finds that a directory only has the last modification timestamp but not the latest modification timestamp, it determines that the directory has been deleted, and the electronic device deletes all information related to these directories in its own database. By implementing the method of the embodiment of the present invention, the electronic device can quickly find the deleted directory and update the file scanning results of the storage device in the database.

[0012] In one possible implementation, when the dirty directory set is an empty set, the file scan of the list of files to be scanned is terminated. In an embodiment of the present invention, after the storage device is unplugged, if the user has not modified the files or directories stored in the storage device, the modification timestamps of the files or directories stored in the storage device will not change. When the storage device is connected to the electronic device again, when the electronic device compares the last modification timestamp of the directory with the same file name with the current latest modification timestamp, if the two timestamps corresponding to all directories are consistent and it is determined that the directory has not been modified, the process of performing file scanning on the storage device is terminated. By implementing the method of the embodiment of the present invention, repeated scanning of files that have not been modified can be avoided, thereby reducing the time the user waits for file scanning.

[0013] In one possible implementation, when the dirty directory set is non-empty, a file scan is performed on the dirty directories in the dirty directory set. In this embodiment of the present invention, if a user modifies files or directories stored in the storage device after the storage device is unplugged, the modification timestamps of the modified files or directories will change. If this causes the last modification timestamp of some directories to be inconsistent with the latest modification timestamp, the electronic device will only perform file scans on these directories, avoiding repeated scans of unmodified directories and thus reducing the number of files scanned.

[0014] In one possible implementation, scanning the dirty directories in the dirty directory set includes comparing the first modification timestamp with the second modification timestamp of the dirty directories in the dirty directory set; and deleting the dirty directories whose first modification timestamp and the second modification timestamp are consistent from the dirty directory set. In this embodiment of the present invention, since multiple dirty directories can be scanned in parallel, before scanning each dirty directory, it is possible to determine again whether the last modification timestamp of the dirty directory is consistent with the current latest modification timestamp. If they are consistent, the dirty directory is deleted from the dirty directory set, thereby avoiding repeated scanning of the dirty directories.

[0015] In one possible implementation, attribute information of the dirty directory is recorded; the attribute information includes a second modification timestamp of the dirty directory. In an embodiment of the present invention, before performing a file scan on the modified directory, the latest modification timestamp of the modified directory is recorded to facilitate subsequent updating of the file scan results in the database.

[0016] In one possible implementation, all direct subfiles under the dirty directory are traversed; the direct subfiles include subfiles and subdirectories under the dirty directory. In an embodiment of the present invention, when performing file scanning on a dirty directory, only the direct subfiles of the dirty directory are traversed, and there is no need to traverse the files and directories under the direct subfiles. The reason is that in the embodiment of the present invention, when determining the initial dirty directory set, all directories (including subdirectories) with changed timestamps have been determined as dirty directories, and the embodiment of the present invention will scan the direct subfiles and subdirectories under all dirty directories. Therefore, it is only necessary to scan the files and directories under the direct subfiles under each dirty directory to cover all directories or files with changed timestamps and newly added directories in the storage device. By implementing the method of the embodiment of the present invention, traversing the direct subfiles under the dirty directory can reduce the number of files traversed during the file scanning process, reduce the traversal time, and thus improve the file scanning efficiency.

[0017] In a possible implementation, first sub-file information is obtained; the first sub-file information includes the first modification timestamp of the direct sub-file of the dirty directory in the scanned file list; second sub-file information is obtained; the second sub-file information includes the second modification timestamp of the direct sub-file of the dirty directory in the to-be-scanned file list; the first sub-file information of the direct sub-file with the same file name is compared with the second sub-file information to determine the modified direct sub-file. In an embodiment of the present invention, when the storage device is unplugged, if the user modifies the direct sub-file of the dirty directory stored in the storage device, the modification timestamp of the direct sub-file will change. The last modification timestamp of the direct sub-file is compared with the current latest modification timestamp. If the two timestamps are inconsistent, it is determined that the direct sub-file has been modified. By implementing the method of the embodiment of the present invention, it is possible to more quickly determine whether the direct sub-file under the dirty directory has been modified.

[0018] In a possible implementation, the determination of the modified direct subfile includes: determining that the direct subfile is a modified direct subfile; the modified direct subfile is a direct subfile whose file name is the same as that in the first subfile information and the second subfile information and whose first sub-modification timestamp is inconsistent with the second sub-modification timestamp; determining that the direct subfile is a deleted direct subfile; and the deleted direct subfile is a direct subfile that does not appear in the second subfile information but appears in the first subfile information. In an embodiment of the present invention, if a direct subfile with the same file name has a last modification timestamp and a current latest modification timestamp and these two modification timestamps are inconsistent, it means that the user has modified the direct subfile after the storage device is disconnected, and the direct subfile is determined to be a modified direct subfile. If a direct subfile with the same file name only has a last modification timestamp but not a current latest modification timestamp, it means that the user has deleted the direct subfile after the storage device is disconnected, and the direct subfile is determined to be a deleted direct subfile.

[0019] In one possible implementation, information about deleted direct child files is deleted from the scan results of the scanned file list. In this embodiment of the present invention, when an electronic device discovers that a direct child file only has a last modification timestamp but not a current modification timestamp, it determines that the directory has been deleted and deletes all information related to these direct child files from its database. By implementing the method of this embodiment of the present invention, the electronic device can quickly identify deleted direct child files and update the storage device's file scan results in its database.

[0020] In one possible implementation, it is determined whether the modified direct child file is a directory; if not, the modified direct child file is determined to be a modified child file, the file attributes of the modified child file are obtained, the modified child file is parsed, and the scan result of the modified child file is updated in the scan result of the scanned file list; if so, the modified direct child file is determined to be a modified subdirectory, the directory attributes of the modified subdirectory are obtained, the first sub-modification timestamp of the modified subdirectory is set to a negative number, and the scan result of the modified subdirectory is inserted into the scan result of the scanned file list. In an embodiment of the present invention, after the modified direct child file in the dirty directory is found, the modified child file is re-parsed and the file scan result of the modified child file is updated in the database of the electronic device; when a modified subdirectory is found, the last modification timestamp of the modified subdirectory is set to a negative number, because under normal circumstances, the value of the modification timestamp is a number greater than 0, and setting it to a negative number means marking the modified subdirectory as dirty. The timestamp set to negative will not be changed to the current latest timestamp until the relevant information of the modified subdirectory is successfully updated. This ensures that these modified subdirectories can be considered dirty directories under any circumstances before the update is completed (because the negative timestamp will definitely be different from any normal timestamp).

[0021] In one possible implementation, inserting the scan result of the modified subdirectory into the scan result of the scanned file list further includes: determining whether the scan result of the modified subdirectory is successfully inserted into the scan result of the scanned file list; if the insertion is successful, adding the modified subdirectory to the dirty directory set. In this embodiment of the present invention, after the modification timestamp of the modified subdirectory is set to a negative number, the modified subdirectory is inserted into the scan result. If the insertion is successful, the modified subdirectory is considered a newly added directory and is added to the dirty directory set.

[0022] In one possible implementation, the method further includes determining that all of the direct child files of the dirty directory have been traversed; and updating the scan results of the current dirty directory; wherein the scan results of the current dirty directory include the first modification timestamp of the dirty directory. Optionally, when a directory with a negative modification timestamp is found, the negative value of the timestamp is updated to the current latest modification timestamp. In this embodiment of the present invention, after traversing all direct child files of a dirty directory, the first modification timestamp of the dirty directory is updated to the current latest modification timestamp, thereby ultimately updating the scan results of the dirty directory in the electronic device's database.

[0023] In one possible implementation, the first modification timestamps of directories in all scan results within the time period T3-ΔT are set to negative numbers; T3 is the time when the storage device unmount message is received; and ΔT is a preset time period. Optionally, ΔT is an empirical time difference derived from different systems. It should be noted that ΔT is typically greater than or equal to (T3-T1), where T1 is the time when the storage device is disconnected from the electronic device. In an embodiment of the present invention, by setting the first modification timestamps of directories in all scan results within the time period T3-ΔT to negative numbers, when the electronic device performs a file scan on the storage device again, since the negative timestamps are necessarily inconsistent with any normal timestamps, they will be identified as dirty directories during the process of forming dirty directories, and thus these files will be retraversed and parsed. This approach avoids the problem of inconsistent results obtained by calling the file system interface when the storage device is hot-plugged or abnormally interrupted, improving the stability of file scanning and enhancing usability in practical scenarios.

[0024] In a second aspect, the present application provides a document scanning device, which may include:

[0025] A receiving module, configured to receive a scan request for a target storage device;

[0026] A first acquisition module is configured to acquire first file information; the first file information includes first directory information of a scanned file list stored in the target storage device, the first directory information including a first modification timestamp of each directory in the scanned file list;

[0027] a second acquiring module, configured to acquire second file information, the second file information including second directory information of the to-be-scanned file list stored in the target storage device, the second directory information including a second modification timestamp of each directory in the to-be-scanned file list;

[0028] A processing module is used to compare the first directory information with the second directory information to generate a dirty directory set; the dirty directories in the dirty directory set are directories whose file names are the same as those in the first directory information and the second directory information and whose first modification timestamp is inconsistent with the second modification timestamp, or directories that appear in the second directory information but do not appear in the first directory information.

[0029] In an embodiment of the present invention, in a file scanning device, a receiving module first receives a file scanning request, a first acquisition module acquires first file information, a second acquisition module acquires second file information, a processing module compares first directory information in the acquired first file information with second directory information in the acquired second file information, and then the processing module traverses the modified directory, avoiding a full disk traversal of the storage device, reducing the number of traversed files, shortening the traversal time, and improving file scanning efficiency. In one possible implementation, the first acquisition module is specifically used to: search for the first file information that matches the universal unique identifier (UUID) of the storage device based on the UUID.

[0030] In a possible implementation, the processing module is specifically configured to: if no directory exists in the first directory information, add the root directory of the to-be-scanned file list stored in the storage device to the dirty directory set.

[0031] In one possible implementation, the device also includes: a deletion module, which is used to delete the directory to be deleted from the first directory information after comparing the first directory information with the second directory information, and delete the scanning results corresponding to the directory to be deleted; the directory to be deleted is a directory that appears in the first directory information and does not appear in the second directory information.

[0032] In a possible implementation, the processing module is specifically configured to: when the dirty directory set is an empty set, end the file scanning of the to-be-scanned file list.

[0033] In a possible implementation, the processing module is specifically configured to: when the dirty directory set is a non-empty set, perform file scanning on the dirty directories in the dirty directory set.

[0034] In one possible implementation, the processing module and the deletion module are specifically used: the processing module is used to compare the first modification timestamp with the second modification timestamp of the dirty directory in the dirty directory set; the deletion module is used to delete the dirty directory whose first modification timestamp is consistent with the second modification timestamp from the dirty directory set.

[0035] In a possible implementation, the apparatus further includes: a recording module configured to record attribute information of the dirty directory; the attribute information includes a second modification timestamp of the dirty directory.

[0036] In a possible implementation, the processing module is specifically configured to: traverse all direct sub-files under the dirty directory; the direct sub-files include sub-files and sub-directories under the dirty directory.

[0037] In one possible implementation, the first acquisition module, the second acquisition module and the processing module are specifically used: the first acquisition module is used to obtain first sub-file information; the first sub-file information includes the first sub-modification timestamp of the direct sub-file of the dirty directory in the scanned file list; the second acquisition module is used to obtain second sub-file information; the second sub-file information includes the second modification timestamp of the direct sub-file of the dirty directory in the to-be-scanned file list; the processing module is used to compare the first sub-file information and the second sub-file information of the direct sub-files with the same file name to determine the modified direct sub-file.

[0038] In one possible implementation, the processing module is specifically used to: determine that the direct subfile is a modified direct subfile; the modified direct subfile is a direct subfile whose file name is the same as that in the first subfile information and the second subfile information and whose first sub-modification timestamp is inconsistent with that in the second sub-modification timestamp; determine that the direct subfile is a deleted direct subfile; the deleted direct subfile is a direct subfile that does not appear in the second subfile information but appears in the first subfile information.

[0039] In a possible implementation, the deleting module is specifically configured to delete information of the deleted direct sub-files in the scanning result of the scanned file list.

[0040] In one possible implementation, the processing module is specifically used to: determine whether the modified direct subfile is a directory; if not, determine that the modified direct subfile is a modified subfile, obtain the file attributes of the modified subfile, perform file parsing on the modified subfile and update the scan result of the modified subfile in the scan result of the scanned file list; if so, determine that the modified direct subfile is a modified subdirectory, obtain the directory attributes of the modified subdirectory, set the first sub-modification timestamp of the modified subdirectory to a negative number, and insert the scan result of the modified subdirectory into the scan result of the scanned file list.

[0041] In one possible implementation, the processing module is specifically configured to: determine whether the scan result of the modified subdirectory is successfully inserted into the scan result of the scanned file list; and if the insertion is successful, add the modified subdirectory to the dirty directory set.

[0042] In one possible implementation, the processing module is specifically configured to:

[0043] Determine that all direct subfiles of the dirty directory have been traversed; update the current scan result of the dirty directory; the current scan result of the dirty directory includes a first modification timestamp of the dirty directory.

[0044] In one possible implementation, the processing module is specifically configured to set the first modification timestamp of the directory in all scan results within a time period of T3-ΔT to a negative number; T3 is the time when the storage device uninstallation message is received; and ΔT is a preset time period.

[0045] In a third aspect, the present application provides a computer storage medium, which may include: computer software instructions for storing a processing module in a document scanning device provided in the second aspect, which includes a program designed for executing the above aspect.

[0046] In a fourth aspect, the present application provides a computer program, which may include: the computer program includes instructions, and when the computer program is executed by a computer, the computer can execute the process executed by the processing module in the file scanning device in the second aspect above.

[0047] In a fifth aspect, an embodiment of the present invention provides an electronic device comprising a processor configured to support the electronic device in implementing the corresponding functions of the file scanning method provided in the first aspect. The electronic device may further include a memory coupled to the processor and storing program instructions and data necessary for the electronic device. The electronic device may further include a communication interface for communicating with other devices or a communication network.

[0048] In a sixth aspect, the present application provides a chip system, which includes a processor for supporting an electronic device in implementing the functions described in the first aspect, such as generating or processing information used in the document scanning method. In one possible design, the chip system further includes a memory for storing program instructions and data necessary for the electronic device. The chip system may consist of a chip or may include a chip and other discrete components. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Figure 1 This is a schematic diagram of a file scanning system architecture provided by an embodiment of the present invention.

[0050] Figure 2 The present invention provides a schematic diagram of a file scanning system architecture of an electronic device.

[0051] Figure 3 The present invention provides a flowchart of a method for scanning a document.

[0052] Figure 4 This is a schematic diagram of first access file information provided by an embodiment of the present invention.

[0053] Figure 5 This is a schematic diagram of re-accessing file information provided by an embodiment of the present invention.

[0054] Figure 6A The present invention provides a flowchart of a process for generating a dirty directory set by scanning a file.

[0055] Figure 6B This is a schematic diagram of a file scanning process provided by an embodiment of the present invention.

[0056] Figure 7A This is a schematic diagram of the first file information and the second file information when the mobile hard disk provided by an embodiment of the present invention is inserted into the smart screen for the first time.

[0057] Figure 7B This is a schematic diagram of direct sub-file information under a root directory accessed for the first time by a storage device provided by an embodiment of the present invention.

[0058] Figure 8A This is a schematic diagram of first sub-file information and second sub-file information of a direct sub-file of directory A provided by an embodiment of the present invention.

[0059] Figure 8B This is a schematic diagram of first sub-file information and second sub-file information of a direct sub-file of the C directory provided by an embodiment of the present invention.

[0060] Figure 8C This is a schematic diagram of first sub-file information and second sub-file information of a direct sub-file of the X directory provided by an embodiment of the present invention.

[0061] Figure 9 This is a schematic diagram of file scanning when a storage device is first accessed, provided by an embodiment of the present invention.

[0062] Figure 10 This is a schematic diagram of the first file information and the second file information when the mobile hard disk provided by an embodiment of the present invention is inserted into the smart screen again.

[0063] Figure 11A This is a schematic diagram of first sub-file information and second sub-file information of a direct sub-file of directory A inserted again, provided by an embodiment of the present invention.

[0064] Figure 11B This is a schematic diagram of first sub-file information and second sub-file information of a direct sub-file of a C directory inserted again provided by an embodiment of the present invention.

[0065] Figure 11C This is a schematic diagram of first sub-file information and second sub-file information of a direct sub-file of the E directory provided by an embodiment of the present invention.

[0066] Figure 12 This is a schematic diagram of a storage device provided by an embodiment of the present invention being connected to a file scan again.

[0067] Figure 13 It is a structural schematic diagram of a document scanning device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0068] The embodiments of the present invention will be described below with reference to the accompanying drawings.

[0069] The terms "first," "second," "third," and "fourth," etc., in the specification and claims of this application and the accompanying drawings are used to distinguish between different objects, rather than to describe a specific order. In addition, the terms "including," "having," and any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or elements is not limited to the listed steps or elements, but may optionally include steps or elements not listed, or may optionally include other steps or elements inherent to the process, method, product, or apparatus.

[0070] References herein to "embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute an independent or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0071] Below, some terms in this application are explained to facilitate understanding by those skilled in the art.

[0072] (1) A Universally Unique Identifier (UUID) is a 128-bit value. No two UUIDs have the same value.

[0073] (2) File System (FS): A file system is the method and data structure used by an operating system to identify files on a disk or partition. This refers to the method by which files are organized on a disk. It also refers to the disk or partition used to store files, or the type of file system.

[0074] (3) Virtual File System (VFS) The function of a virtual file system is to call read and write different file systems located on different physical media, that is, to provide a unified operation interface and application programming interface for various file systems. VFS is a glue layer that allows system calls such as open(), read(), and write() to work without considering the underlying storage medium and file system type.

[0075] First, we analyze and propose the technical problems that this application aims to solve. The existing technologies for document scanning include the following: Solution 1 and Solution 2:

[0076] Solution 1: Each time a storage device is connected to an electronic device, a full disk traversal and full disk file parsing process must be performed. Specifically, the process may include the following steps 1-5:

[0077] Step 1: A storage device is connected to an electronic device, and an operating system of the electronic device starts a media scanning process to scan a list of files to be scanned stored in the storage device.

[0078] Step 2: The electronic device traverses the list of files to be scanned stored in the storage device to obtain all information of all files in the list of files to be scanned in the storage device.

[0079] Step 3: During the traversal process, if the electronic device finds a media file in the list of files to be scanned stored in the storage device, the electronic device parses the media file to obtain a parsing result of the media file. For example, the electronic device parses a picture-type media file to generate a thumbnail of the picture-type media file.

[0080] Step 4: The electronic device temporarily stores the scanning result of the list of files to be scanned stored in the storage device in a media database of the electronic device.

[0081] Step 5: The storage device is disconnected from the electronic device, and the electronic device clears the corresponding file scanning results stored in the media database that are obtained by scanning the files on the storage device.

[0082] Solution 1 has many application scenarios and a low scanning method complexity, but it has the following disadvantages:

[0083] Disadvantage 1: The electronic device's file scanning process combines file traversal and media file parsing, which is time-consuming. When the storage device has a large capacity and many media files, the scanning time is long and the scanning efficiency is low.

[0084] Disadvantage 2: On some electronic devices, such as smart screens, external storage devices are frequently plugged in and out. The file scan of the current electronic device will clear the scan results of the external storage device. When the storage device is connected again, the entire disk will be traversed and analyzed again, resulting in a long scanning time and low scanning efficiency.

[0085] Solution 2: For different storage devices, respectively establish a file information database corresponding to the storage device. After the storage device is disconnected, the content of the corresponding file information database is not cleared. Specifically, the following steps 1-5 may be included.

[0086] Step 1: The storage device is connected to the electronic device, and the electronic device traverses all files in the list of files to be scanned stored in the storage device to obtain all file information in the list of files to be scanned stored in the storage device.

[0087] Step 2: The electronic device performs matching based on the storage device information, finds a file information database that matches the storage device, and determines whether a corresponding file parsing result exists in the file information database.

[0088] Step 3: If the file information database contains the file parsing result of the storage device, compare the data in the file information database with the traversed full disk file information. If it is found that the file has not been modified, skip the file parsing step for the file.

[0089] Step 4: If the file has been modified, reparse the file.

[0090] Step 5: The electronic device writes the file scanning result of the list of files to be scanned stored in the storage device into the file information database corresponding to the storage device, and saves the file scanning result.

[0091] Solution 2 avoids re-parsing unmodified files when re-accessing the storage device, improving file scanning efficiency. However, it also has the following disadvantages:

[0092] Disadvantage 1: When the storage device has a large storage capacity and stores a large number of files, it is very time-consuming for the electronic device to traverse the entire storage device and obtain all file information in the list of files to be scanned on the storage device.

[0093] In summary, the existing file scanning method takes a long time to scan and has low scanning efficiency when the storage device has a large storage capacity and a large number of files, resulting in a poor user experience. Therefore, the file scanning method provided in this application is used to solve the above technical problems.

[0094] To facilitate understanding of the embodiments of the present invention, the following examples illustrate scenarios in which the file scanning method in this application is applied. These scenarios may include the following two:

[0095] Scenario 1: Frequently inserting a mobile hard disk into a smart screen scenario. In this scenario, the mobile hard disk corresponds to the storage device in the embodiment of the present invention, and the smart screen corresponds to the electronic device in the embodiment of the present invention. With the development of science and technology, smart screens have been derived on the basis of traditional televisions. Smart screens play multiple roles in the home. They are not only a home audio-visual entertainment center, but also an information sharing center, a control management center, and a multi-device interaction center. The smart screen displays the file information stored in the mobile hard disk by connecting to the mobile hard disk, such as watching movies stored in the mobile hard disk through the smart screen. After the smart screen is connected to the mobile hard disk, it will scan the stored files and then play the movies stored in the mobile hard disk. If the same mobile hard disk is plugged in and out of the same smart screen multiple times, the file scanning method in this application can shorten the time the user waits for the file scan, improve the file scanning efficiency, and thus enhance the user experience.

[0096] Scenario 2: Synchronizing and backing up files in a cloud disk to a personal computer. In this scenario, the cloud disk corresponds to the storage device in the embodiment of the present invention, and the personal computer corresponds to the electronic device in the embodiment of the present invention. In today's world where the amount of information is increasing dramatically, users have a lot of videos, pictures, texts and other materials that they want to view on their personal computers. At the same time, users have an increasing demand for instant viewing of personal information. Under the condition that the data is not lost and is sufficiently private, users are willing to upload their personal information to a cloud disk and use the cloud disk for storage. In the process of synchronizing and backing up files in a cloud disk to a personal computer, it is necessary to perform a full disk scan on the files in the cloud disk. In order to increase the speed of file scanning, before performing a full disk scan on the cloud disk, the file scanning method in this application can be used to more quickly identify files that need to be synchronized and backed up, avoiding a full disk scan, thereby improving the efficiency of synchronizing and backing up files in the cloud disk to a personal computer.

[0097] It can be understood that the above two application scenarios are only several exemplary implementations in the embodiments of the present invention. The application scenarios in the embodiments of the present invention include but are not limited to the above application scenarios.

[0098] The embodiments of the present application are described below with reference to the accompanying drawings.

[0099] Based on the above-mentioned technical problems and the corresponding application scenarios in this application, and in order to facilitate understanding of the embodiments of the present invention, the system architecture based on which the embodiments of the present invention are based is described below. Figure 1 , Figure 1This is a schematic diagram of a file scanning system architecture provided by an embodiment of the present invention. The system is used to solve the problem of low file scanning efficiency caused by frequent plugging and unplugging of storage devices on the same electronic device. The system architecture may include storage devices and electronic devices.

[0100] Storage device 101, in this application, refers to a device for storing information, which usually digitizes the information and then stores it using electrical, magnetic, or optical media. Common storage devices include memory, hard disks, USB flash drives, cloud drives, and other devices. For example, a mobile hard disk often uses USB or IEEE1394 interfaces, which can be plugged in or unplugged at any time. It is small and easy to carry, and can transmit data to the system at a high speed. The mobile hard disk can transmit data to the system of the electronic device by connecting it to the interface of the electronic device.

[0101] Electronic device 102, in this application, refers to an electronic device with an operating system and a data transmission interface. Common electronic devices include smart screens, personal computers, tablets, and other devices. For example, a smart screen is derived from a traditional TV screen. The smart screen has data transmission interfaces such as USB and HDMI interfaces, and can be connected to storage devices such as mobile hard drives, USB flash drives, and USB card readers. When a storage device is connected, the smart screen will establish data transmission with the storage device and obtain the storage content in the storage device.

[0102] It is understandable that Figure 1 The file scanning system architecture in the embodiment of the present application is only an exemplary implementation. The file scanning system architecture in the embodiment of the present application includes but is not limited to the above system architecture.

[0103] The following describes the file scanning system architecture of the electronic device according to the embodiment of the present invention. Figure 2 , Figure 2 2 is a schematic diagram of a file scanning system architecture of an electronic device provided by an embodiment of the present invention. The file scanning system architecture includes a request processing module 201 , a traversal module 202 , a parsing module 203 and a data module 204 .

[0104] The request processing module 201 is responsible for processing external scan requests. For example, the request module includes a broadcast receiver and a scan manager. Upon receiving a scan request broadcast from the Android kernel or a third-party application, the broadcast receiver sends an instruction to the scan manager, prompting the scan manager to issue a file scan request to the request handler in the traversal module.

[0105] The traversal module 202 is responsible for traversing the modified or newly added directories and their direct sub-files on the corresponding storage device. For example, the traversal module includes a request processor, a scanning task queue and a task pool. After receiving the message from the request processing module, the request processor will search for the first file information of the corresponding storage device based on the universal unique identifier (UUID) of the storage device, and then find the first modification timestamp of the directory based on the first directory information in the first file information, and then compare it with the second modification timestamp of the current directory to obtain a dirty directory set. According to the scanning task queue, the dirty directories are placed in the task pool, and the dirty directories are traversed. When new directories or new dirty directories are found, these directories are added to the scanning task queue.

[0106] The parsing module 203 is responsible for parsing files. For example, when a file needs to be parsed, the parsing module creates a file object, obtains the file encoding and reads the file stream, then reads the file information stream, caches it in memory, and then reads the file information. After processing, the parsing process is completed, such as obtaining a thumbnail of the media file after parsing.

[0107] The data module 204 is responsible for storing the scanned data. For example, after completing the file traversal and parsing, the database will record the scan results of this file, including the file parsing results and the updated directory entry information. The information recorded in the database includes but is not limited to the path, parent path, modification timestamp, and file type.

[0108] For example, suppose that in scenario 1, a mobile hard disk is frequently connected to a smart screen. In this scenario, the mobile hard disk corresponds to the storage device in the embodiment of the present invention, and the smart screen corresponds to the electronic device in the embodiment of the present invention. When the mobile hard disk is inserted into the smart screen interface again, the file scanning request processing module 201 receives a scan request broadcast initiated by the Android kernel or a third-party application, and sends an instruction to the scan manager to initiate a scan of the files stored in the mobile hard disk.

[0109] The data module 204 retrieves the directory information recorded in the last scan of the mobile hard disk according to the universal unique identifier (UUID) of the storage device, and compares it with the directory information during the current access to form a dirty directory set.

[0110] The traversal module 202 traverses the dirty directory set to obtain all file information of all subdirectories and direct subfiles under the dirty directory. Then, the modified file is found and the parsing module 203 reparses the modified file.

[0111] Finally, the data module 204 will update and save the results of this scan. If the mobile hard disk is connected to the smart screen for the first time, all file root directories in the mobile hard disk are added to the dirty directory set for traversal.

[0112] The following describes the specific method architecture on which the embodiments of the present invention are based. Figure 3 , Figure 3 This is a flowchart of a file scanning method in an embodiment of the present application. Figure 3 Based on the above Figure 1 The file scanning system architecture in the present application describes the file scanning method in the embodiment of the present application from the perspective of the interaction between the storage device and the electronic device. It should be noted that in order to describe the file scanning method in the embodiment of the present application in more detail, the present application describes the corresponding execution subject as an electronic device in each process step, but this does not mean that the embodiment of the present application can only perform the corresponding method process through the described execution subject.

[0113] Step S301: receiving a scan request for a target storage device and obtaining first file information.

[0114] Specifically, the first file information includes the first directory information of the file scanning result stored in the database after the electronic device scans the storage device for files when the storage device is connected to the electronic device last time. The first directory information is the information of all directories in the scanning result. The first modification timestamp is the modification timestamp of the directory recorded after the file scanning of the storage device is completed last time. For example, Figure 4 、 Figure 5 The diagram shows the first access file information and the second access file information. When the storage device is first accessed, the file information stored in the electronic device is empty, so the first file information is empty. When the storage device is accessed again, the file information stored in the electronic device is empty. Figure 5 As shown, the first directory information in the first file information includes the root directory " / ", directory A, directory C, and directory X. The first modification timestamp of directory A is 8:00, the first modification timestamp of directory C is 8:00, and the first modification timestamp of directory X is 5:00. It is understandable that the above-mentioned first file information can be obtained by scanning after the storage device is first connected to the electronic device, or can be obtained by scanning after the storage device is connected to the electronic device multiple times.

[0115] Step S302: Obtain second file information.

[0116] Specifically, after the last scanning process of the storage device is completed and the storage device is disconnected, the user may modify, delete, or add files stored in the storage device. When the storage device is connected to the electronic device again, the electronic device obtains the second file information. The second file information includes the second directory information obtained by the electronic device based on the list of files to be scanned stored in the storage device when the storage device is connected to the electronic device this time. The second directory information is all directory information of the list of files to be scanned, and the second modification timestamp is the modification time of the most recent modification record of the directory. For example, Figure 4 、 Figure 5 The following are the schematic diagrams of file information accessed for the first time and file information accessed again. When the storage device is accessed for the first time, the file information stored in the storage device is as follows: Figure 4 As shown, the second directory information in the second file information includes the root directory " / ", directory A, directory C and directory X. The second modification timestamp of directory A is 8:00, the second modification timestamp of directory C is 8:00, and the second modification timestamp of directory X is 5:00. When the storage device is connected again, the file information stored in the storage device is as follows Figure 5 As shown, the second directory information in the second file information includes the root directory " / ", directory A, directory C, directory X, and directory E. The second modification timestamp of directory A is 10:00, the second modification timestamp of directory C is 9:00, the second modification timestamp of directory X is 5:00, and the second modification timestamp of directory E is 10:00.

[0117] Step S303: Compare the first directory information with the second directory information to generate a dirty directory set.

[0118] Specifically, the electronic device compares the first modification timestamp and the second modification timestamp of the directory with the same file name in the first directory information and the second directory information. If the two timestamps are inconsistent, the directory is recorded as a dirty directory and added to the dirty directory set. Figure 4 、 Figure 5 In the example, when the storage device is first connected, only the root directory " / " is added to the dirty directory set. When the storage device is connected again, the first modification timestamps of directories A, C, and X are compared with the second modification timestamps. If they are inconsistent, directories A and C are added to the dirty directory set.

[0119] It should be further explained that, extracting dirty directories from the dirty directory set and traversing the direct sub-files under the dirty directory can greatly reduce the number of files to be traversed in the list of files to be scanned stored in the storage device. The direct sub-files include the sub-directories and sub-files under the dirty directory. For example, Figure 5In the file information stored in the electronic device, “ / ” is the root directory. The direct sub-files of the root directory are A directory, X directory, and C directory.

[0120] By using the method of an embodiment of the present invention, when the electronic device is reconnected to the storage device, the electronic device can more quickly locate the modified or newly added files, perform file parsing on the modified or newly added files, and update the scan results of the scanned file list in the electronic device database. This provides a new file scanning method that reduces the time required to re-insert the storage device while waiting for the electronic device to scan the list of files to be scanned stored on the storage device, thereby improving file scanning efficiency and enhancing the user experience.

[0121] When the electronic device performs a file scan on the list of files to be scanned stored in the storage device, the operating system of the electronic device can be an Android system or other operating systems. When the electronic device receives a file scan request, as long as a dirty directory set is first formed and only the direct sub-files under the dirty directory need to be traversed, the number of files to be traversed can be greatly reduced, the problems in the existing technology can be solved, and corresponding effects can be achieved.

[0122] The following describes the specific method architecture on which the embodiments of the present invention are based. Figure 6A and Figure 6B , Figure 6A This is a detailed flowchart of a file scanning and generation of a dirty directory set in an embodiment of the present application. Figure 6B This is a schematic diagram of a file scanning process provided by an embodiment of the present invention. Figure 6A and Figure 6B Based on the above Figure 1 The file scanning system architecture in the present application describes the file scanning method in the embodiment of the present application from the perspective of the interaction between the storage device and the electronic device. It should be noted that in order to describe the file scanning method in the embodiment of the present application in more detail, the present application describes the corresponding execution subject as an electronic device in each process step, but this does not mean that the embodiment of the present application can only perform the corresponding method process through the described execution subject.

[0123] Step S601: receiving a scan request for a target storage device.

[0124] Specifically, in an embodiment of the present invention, the electronic device needs to receive a scan request for the target storage device before performing a file scan on the storage device. Before the electronic device receives the scan request, different storage devices connected to the electronic device need to be mounted. Therefore, after the storage device is connected to the electronic device, the electronic device analyzes the file system structure stored in the storage device for the storage device, and obtains the file system type supported by the operating system of the electronic device. The operating system calls the corresponding driver according to the file system type of the storage device, processes its metadata, and then appends the information to the directory tree and presents it, so that the operating system of the electronic device incorporates the storage device into its own file system and completes the mount operation. After completing the mount operation, the operating system (such as the Android system) will send this mount broadcast. After the electronic device receives the mount broadcast, it will perform a file scan on the target storage device.

[0125] Step S602: Obtain first file information.

[0126] In a possible implementation, the obtaining of the first file information includes searching for the first file information that matches the universal unique identifier (UUID) of the storage device according to the UUID. Specifically, since the electronic device will set a UUID for each storage device and the UUID corresponding to each storage device is different, when the storage device is connected to the electronic device again, the electronic device will search the database for the latest scan result of the corresponding storage device according to this UUID. It should be noted that the first file information includes information about some directories saved in the electronic device database the last time the storage device was connected to the electronic device. The first directory information of the scanned file list stored in the storage device is obtained based on the first file information, and the first directory information includes the first modification timestamp of each directory in the scanned file list, and the first modification timestamp is the last modification timestamp of each directory saved in the electronic device database after the file scan is completed.

[0127] Step S603: Obtain second file information.

[0128] Specifically, after the storage device is mounted in the system of the electronic device, the operating system of the electronic device incorporates the storage device into its own file system, and the electronic device can obtain second file information. The second file information includes some directory information in the list of files to be scanned stored by the target storage device, and the second directory information includes a second modification timestamp for each directory in the list of files to be scanned, which is the modification timestamp recorded after the most recent modification of each directory in the list of files to be scanned stored by the storage device.

[0129] Optionally, after the first file information and the second file information are obtained, step S6031 is executed to represent the first modification timestamp in the obtained first file information as t, and the obtained second modification timestamp as t'.

[0130] Step S604: Compare the first directory information with the second directory information to generate a dirty directory set.

[0131] Specifically, after the electronic device obtains the results of the last file scan on the storage device, it can obtain the last modification timestamps of all directories based on the scan results, compare the last modification timestamps corresponding to all directories with the current latest modification timestamps, and if it is found that the last modification timestamp of the directory with the same file name is inconsistent with the current latest modification timestamp, step S6042 is executed to add the directory to the dirty directory set, thereby generating an initial dirty directory set. If the last modification timestamp of the directory with the same file name is consistent with the current latest modification timestamp, step S6041 is executed, indicating that the directory and its direct child files have not been modified and no new files have been added.

[0132] In one possible implementation, generating a dirty directory set includes, if no directory exists in the first directory information, adding the root directory of the to-be-scanned file list stored on the storage device to the dirty directory set. Specifically, when a storage device is connected to an electronic device for the first time, the electronic device's database does not contain a record of the storage device's scan results. In this case, initially, only the root directory of the files stored on the storage device is recorded as a dirty directory. The root directory is then traversed, and if any new directories or dirty directories are discovered during the traversal, they are added to the dirty directory set.

[0133] In one possible implementation, after comparing the first directory information with the second directory information, it also includes deleting the directory to be deleted from the first directory information, and deleting the scanning result corresponding to the directory to be deleted; the directory to be deleted is a directory that appears in the first directory information and does not appear in the second directory information. Specifically, when the storage device is unplugged, if the user deletes some directories stored in the storage device, then when the electronic device is connected again, these deleted directories will not have the latest modification timestamp, but the database of the electronic device will have the last modification timestamp of these directories. When the electronic device finds that a directory only has the last modification timestamp but not the latest modification timestamp, it determines that the directory has been deleted, and the electronic device deletes all information related to these directories in its own database.

[0134] Step S605: Determine whether the dirty directory set is an empty set.

[0135] Specifically, when the electronic device begins scanning files on the dirty directory set, it first determines whether the dirty directory set is an empty set. In one possible implementation, if the dirty directory set is an empty set, the file scan of the to-be-scanned file list ends. Specifically, after the storage device is unplugged, if the user has not modified the files or directories stored in the storage device, the modification timestamps of the files or directories stored in the storage device will not change. When the storage device is re-plugged into the electronic device, the electronic device compares the last modification timestamp of directories with the same file name with the latest modification timestamp. If the two timestamps for all directories are consistent, the electronic device determines that the directory has not been modified, executes step S6051, and ends the file scan process on the storage device. In one possible implementation, if the dirty directory set is not an empty set, the file scan is performed on the dirty directories in the dirty directory set. Specifically, after the storage device is unplugged, if the user modifies the files or directories stored in the storage device, the modification timestamps of the modified files or directories will change. Therefore, if the last modification timestamp of some directories is inconsistent with the latest modification timestamp, the electronic device executes step S6052 to extract the dirty directories from the dirty directory set and then scan the files on the dirty directories. It should be noted that the process of extracting the dirty directories from the dirty directory set and scanning the files can be performed on multiple dirty directories simultaneously.

[0136] In one possible implementation, scanning the dirty directories in the dirty directory set includes comparing the first modification timestamp with the second modification timestamp of the dirty directories in the dirty directory set; and deleting from the dirty directory set any dirty directories whose first modification timestamp matches the second modification timestamp. Specifically, because the electronic device can perform file scans on multiple dirty directories simultaneously, before scanning each dirty directory, step S6053 is executed to re-determine whether the last modification timestamp of the dirty directory matches the current latest modification timestamp. If they match, the dirty directory is deleted from the dirty directory set, thereby avoiding repeated scanning of the dirty directories.

[0137] Step S606: Record the attribute information of the dirty directory.

[0138] Specifically, the electronic device records attribute information of the dirty directory, wherein the attribute information includes a second modification timestamp of the dirty directory. Before performing a file scan on the modified directory, the electronic device records the latest modification timestamp of the modified directory to facilitate subsequent updating of the file scan results in the database.

[0139] Step S607: traverse all direct sub-files under the dirty directory.

[0140] Specifically, the electronic device traverses all direct subfiles under the dirty directory; the direct subfiles include subfiles and subdirectories under the dirty directory. When performing file scanning on a dirty directory, only the direct subfiles of the dirty directory are initially traversed, and the corresponding files and directories under the direct subfiles do not need to be considered. The reason is that in the embodiment of the present invention, when determining the initial dirty directory set, all directories (including subdirectories) with changed timestamps have been determined as dirty directories, and the embodiment of the present invention will scan the direct subfiles and subdirectories under all dirty directories. Therefore, it is only necessary to scan the files and directories under the direct subfiles under each dirty directory to cover all directories or files with changed timestamps and newly added directories in the storage device.

[0141] In one possible implementation, first sub-file information is obtained; the first sub-file information includes the first modification timestamp of the direct sub-file of the dirty directory in the scanned file list; second sub-file information is obtained; the second sub-file information includes the second modification timestamp of the direct sub-file of the dirty directory in the to-be-scanned file list; the first sub-file information of the direct sub-file with the same file name is compared with the second sub-file information to determine the modified direct sub-file. Specifically, when the electronic device traverses the direct sub-files under the dirty directory, the electronic device first executes step S6071 to obtain the first sub-file information and the second sub-file information. It should be noted that the first sub-file information includes the last modification timestamp of the direct sub-file of the dirty directory in the scanned file list stored by the target storage device and other information about the direct sub-file scan result. The second sub-file information includes the current latest modification timestamp of the direct sub-file of the dirty directory in the to-be-scanned file list stored by the target storage device and other information about the direct sub-file.

[0142] Next, the electronic device executes step S6072, and the electronic device compares the last modification timestamp of the direct subfile of the dirty directory with the same file name with the current latest modification timestamp. Because when the storage device is unplugged, if the user changes the direct subfile of the dirty directory stored in the storage device, it will cause the modification timestamp of the direct subfile to change. The last modification timestamp of the direct subfile is compared with the current latest modification timestamp. If the two timestamps are inconsistent, it is determined that the direct subfile has been modified. When the last modification timestamp of the direct subfile is consistent with the current latest modification timestamp, step S6073 is executed, and the electronic device continues to traverse other direct subfiles under the dirty directory. When the last modification timestamp of the direct subfile is inconsistent with the current latest modification timestamp, it is determined that the direct subfile has been modified.

[0143] In one possible implementation, determining the modified direct subfile includes: determining that the direct subfile is a modified direct subfile; the modified direct subfile is a direct subfile whose file name is the same as that in the first subfile information and the second subfile information and whose first sub-modification timestamp is inconsistent with the second sub-modification timestamp; determining that the direct subfile is a deleted direct subfile; and the deleted direct subfile is a direct subfile that does not appear in the second subfile information but appears in the first subfile information. Specifically, if a direct subfile with the same file name has a last modification timestamp and a current latest modification timestamp and the two modification timestamps are inconsistent, it means that the user has modified the direct subfile after the storage device is disconnected, and the direct subfile is determined to be a modified direct subfile. When a direct subfile with the same file name only has a last modification timestamp but not a current latest modification timestamp, it means that the user has deleted the direct subfile after the storage device is disconnected, and the direct subfile is determined to be a deleted direct subfile.

[0144] In one possible implementation, information about the deleted direct child files in the scan results of the scanned file list is deleted. Specifically, when the electronic device finds that a direct child file only has a last modification timestamp but not a current modification timestamp, it determines that the directory has been deleted and deletes all information related to the direct child files from its database.

[0145] After the electronic device finds the modified direct subfile, it executes step S6074. In one possible implementation, it determines whether the modified direct subfile is a directory; if not, it determines that the modified direct subfile is a modified subfile, obtains the file attributes of the modified subfile, performs file parsing on the modified subfile, and updates the scan result of the modified subfile in the scan result of the scanned file list; if so, it determines that the modified direct subfile is a modified subdirectory, obtains the directory attributes of the modified subdirectory, sets the first submodification timestamp of the modified subdirectory to a negative number, and inserts the scan result of the modified subdirectory into the scan result of the scanned file list. Specifically, after finding the modified direct subfile under the dirty directory, the electronic device executes step S6075, re-parses the modified subfile, and then executes step S6076 to update the file scan result of the modified subfile in the database of the electronic device. When a modified subdirectory is found, the electronic device executes S6077 and sets the modification timestamp of the modified subdirectory record to a negative number. Since the modification timestamp is normally a number greater than 0, setting it to a negative number indicates that the modified subdirectory is marked as dirty. The electronic device then executes step S6078 to insert the modified subdirectory into the scan results. The electronic device then executes step S6079 to determine whether the directory insertion was successful. If the insertion was successful, the modified subdirectory is a newly added directory, and step S60710 is executed to add it to the dirty directory set.

[0146] Step S608: Update the scanning result of the current dirty directory.

[0147] Specifically, after traversing all the direct subfiles under the dirty directory, the electronic device changes the value of the last modification timestamp of the dirty directory to the value of the latest modification timestamp, and finally updates the scanning result of the dirty directory in the database of the electronic device.

[0148] In one possible implementation, the first modification timestamp of all scan results within the T3-△T time period is set to a negative number; the T3 is the time when the storage device uninstallation message is received; and the △T is a preset time period. Optionally, the △T is the corresponding empirical time difference obtained according to different systems, that is, the time difference according to different operating systems running on the electronic device. It should be noted that, usually, △T is an empirical value greater than or equal to (T3-T1), and T1 is the time when the storage device is disconnected from the electronic device. Completing the above steps S601-S608 enables faster file scanning. However, in actual use, it is found that when the external storage device is hot-plugged, there may be some abnormalities in the return results of the file system interface, which will lead to inconsistent scanning results. Therefore, in this embodiment, an additional mechanism is designed to ensure the stability of file scanning. In this embodiment of the present invention, by setting the first modification timestamp of directories in all scan results within the time period (T3-ΔT) to a negative number, when the electronic device performs a file scan on the storage device again, the negative timestamp will inevitably be inconsistent with any normal timestamp. Therefore, these directories will be identified as dirty directories during the formation process, and the files will be traversed and parsed again. This method avoids the problem of inconsistent results when calling the file system interface during hot plugging and abnormal interruption of the storage device, improves the stability of file scanning, and enhances usability in real-world scenarios.

[0149] It should be noted that the time when the external storage device is disconnected from the electronic device is recorded as T1, the time when the file system on the external storage device is unmounted on the virtual file system (VFS) is T2, and the time when the electronic device receives the unmount message is T3. Therefore, by effectively processing the scan results written into the data module at T3-T1, the problem of inconsistent scan results can be avoided. The specific operation is to derive the corresponding empirical time difference △T based on different systems. It should be noted that △T is usually greater than or equal to (T3-T1). In this way, the directories scanned in the time period from T3-△T to T3 will have their first modification timestamps changed to negative numbers. In this way, these files will be re-traversed and parsed during the next scan.

[0150] In order to describe the file scanning method in the embodiment of the present application in more detail, the following will be combined with the application scenario 1 and Figure 4 Schematic diagram of first access file information, Figure 5 Referring again to the file information diagram, this embodiment is described in detail.

[0151] In the following scenario, the mobile hard disk corresponds to the storage device in the embodiment of the present invention, and the smart screen corresponds to the electronic device in the embodiment of the present invention. When the mobile hard disk is connected to the smart screen for the first time, the mobile hard disk is first mounted on the smart screen so that the operating system of the smart screen can access the files and directories in the mobile hard disk. After the mobile hard disk is mounted, the first file information corresponding to the mobile hard disk is searched in the database according to the universal unique identification code (UUID) of the mobile hard disk, and then the operating system obtains the second file information, such as Figure 7A As shown, Figure 7A This diagram shows the first and second file information when a mobile hard drive is first inserted into a smart screen. In this figure, the first file information does not contain the first directory information. The second directory information in the second file information contains directories A, X, and C under the root directory. The root directory in the second file information is added to the dirty directory set. Typically, the root directory is " / ." At this point, the dirty directory set contains only one dirty directory: the root directory " / ."

[0152] Then get the first sub-file information and the second sub-file information under the root directory, such as Figure 7B As shown, Figure 7B This is a schematic diagram of the direct sub-file information under the root directory when the storage device is first connected. In the figure, there is no direct sub-file information in the first sub-file information. In the second sub-file information, there is A, whose second modification timestamp is 8:00, X, whose second modification timestamp is 5:00, and C, whose second modification timestamp is 8:00. Then A, X, and C are all directories. The second sub-modification timestamps of these three directories are set to negative numbers respectively, and then the scan results of the three directories are inserted into the scan results of the scanned file list. Since the mobile hard disk is inserted into the smart screen for the first time, the scan results of the scanned file list are empty. The scan results of these three directories can be inserted into the scan results of the scanned file list. Next, add these three directories to the dirty directory set, and record that the second modification timestamp of directory A is changed to 8:00, the second modification timestamp of directory X is changed to 5:00, and the second modification timestamp of directory C is changed to 8:00.

[0153] Then obtain the first sub-file information and the second sub-file information of the direct sub-files of the A directory, the X directory and the C directory, such as Figure 8A As shown, Figure 8A This is a diagram of the first and second sub-file information of the direct sub-files of directory A. In the figure, there is no direct sub-file information in the first sub-file information. In the second sub-file information, there is B, whose second sub-file modification timestamp is 7:00, and C, whose second sub-file modification timestamp is 8:00. Next, if B has file attributes, the smart screen will obtain the file attributes of B and parse the file, then update the scan results of the scanned file list of the sub-files and update the first sub-file modification timestamp of file B in the first sub-file information to 7:00.

[0154] Next, if C is found to have directory attributes, the smart screen will obtain the directory attributes of directory C and set its first modified timestamp to a negative number. The scan result of directory C will be inserted into the scan result of the scanned file list. Since directory C is already in the dirty directory set, the insertion fails. After traversing the direct child files of directory A, the first modified timestamp of directory A will be changed to 8:00.

[0155] Get the first and second sub-file information of the direct sub-files of the C directory, such as Figure 8B As shown, Figure 8B This is a diagram of the first and second sub-file information of the direct sub-files of the C directory. In the figure, there is no direct sub-file information in the first sub-file information, and the second sub-file information contains D, whose second sub-modification timestamp is 8:00. Then, if D has file attributes, the smart screen will obtain the file attributes of D and parse the file, then update the scan results of the scanned file list of the sub-file, and update the first sub-modification timestamp of the D file in the first sub-file information to 8:00. After traversing the direct sub-files of the C directory, the first modification timestamp of the C directory is changed to 8:00.

[0156] Get the first and second sub-file information of the direct sub-file of the X directory, such as Figure 8C As shown, Figure 8C This is a diagram of the first and second sub-file information for a direct sub-file of directory X. In the figure, there is no direct sub-file information in the first sub-file information. The second sub-file information contains file Y, whose second sub-file modification timestamp is 5:00. Next, if Y has file attributes, the smart screen will obtain the file attributes of Y and parse the file. It then updates the scan results of the scanned file list of the sub-files and updates the first sub-file modification timestamp of file Y in the first sub-file information to 5:00. After traversing the direct sub-files of directory X, the first modification timestamp of directory X is changed to 5:00.

[0157] like Figure 9 The figure shows a schematic diagram of file scanning when a storage device is connected for the first time. As shown in the figure, when the mobile hard disk is inserted into the smart screen for the first time, the smart screen completes the file scan on the mobile hard disk. At this time, the file scan results of the scanned file list are saved in the smart screen database.

[0158] When the mobile hard disk is connected to the smart screen again, the mobile hard disk is first mounted on the smart screen so that the operating system of the smart screen can access the files and directories in the mobile hard disk. After the mobile hard disk is mounted, the first file information corresponding to the mobile hard disk is searched in the database according to the universal unique identifier (UUID) of the mobile hard disk, and the operating system obtains the first file information and the second file information, such as Figure 10 As shown, Figure 10 This is a schematic diagram of the first file information and second file information when the mobile hard drive is inserted into the smart screen again. In the figure, the first directory information in the first file information includes directory A, directory X, and directory C, and the second directory information in the second file information includes directory A, directory C, directory X, and directory E. Compare the first modification timestamp and the second modification timestamp of the same file name, and put the two directories with inconsistent timestamps into the dirty directory set. Here, directory A and directory C are put into the dirty directory set. At this time, there are two dirty directories in the dirty directory set. When traversing the dirty directories, the dirty directories can be traversed simultaneously regardless of order. The following example takes the simultaneous scanning of directory A and directory C as an example.

[0159] Take directories A and C from the dirty directory set, compare the first modification timestamps and second modification timestamps of directories A and C respectively to determine that directories A and C are dirty directories at this time, and then record the second modification timestamps of A as 10:00 and C as 9:00 respectively.

[0160] Get the first sub-file information and the second sub-file information of the direct sub-files of directory A and directory C, such as Figure 11A As shown, Figure 11A In the diagram below, the first and second subfile information for the direct subfiles of directory A are inserted again. In the diagram, the first subfile information for file B has a first subfile modification timestamp of 7:00 and C has a first subfile modification timestamp of 8:00. The second subfile information for file B has a second subfile modification timestamp of 7:00, C has a second subfile modification timestamp of 9:00, and E has a second subfile modification timestamp of 10:00. Comparing the first and second subfile modification timestamps of the direct subfiles with the same file name reveals that the first and second subfile modification timestamps for files C and E are inconsistent.

[0161] Next, we find that C is a directory and E is also a directory. We then set the first modification timestamps of these two directories to negative numbers and insert them into the scanned file list. However, since directory C participated in the file scan process when the mobile hard drive was first connected, the insertion fails. Compared to the previous scan results, directory E is a new directory and is therefore successfully inserted into the scanned file list. Next, we add directory E to the dirty directory set and change the first modification timestamp of directory A to the recorded second modification timestamp of 10:00.

[0162] like Figure 11B As shown, Figure 11BTo insert the first sub-file information and the second sub-file information of the direct sub-file of the C directory again, the first sub-file information in the figure has D, whose first sub-modification timestamp is 8:00, and the second sub-file information has D, whose second sub-modification timestamp is 8:30. Comparing the first sub-modification timestamp with the second sub-modification timestamp, it is found that the first sub-modification timestamp of D is inconsistent with the second sub-modification timestamp. Next, if D is a file, the smart screen will obtain the file attributes of D and parse the file, and then update the scan results of the scanned file list of the sub-file, and at the same time update the first sub-modification timestamp of the D file in the first sub-file information to 8:30 and modify the first modification timestamp of the C directory to the recorded second modification timestamp of 9:00.

[0163] The dirty directory E is taken out from the dirty directory set, and the first modification timestamp of the directory E is compared with the second modification timestamp to determine that the directory E is a dirty directory at this time. Then the second modification timestamp of E is recorded as 10:00.

[0164] like Figure 11C As shown, Figure 11C This is a schematic diagram of the first sub-file information and the second sub-file information of the direct sub-file of the E directory. In the figure, there is no direct sub-file information in the first sub-file information, and the second sub-file information contains F, whose second sub-modification timestamp is 9:30. Comparing the first sub-modification timestamp of F with the second sub-modification timestamp, it is found that the first sub-modification timestamp of F is inconsistent with the second sub-modification timestamp. Next, if F is a file, the smart screen will obtain the file attributes of F and parse the file, and then update the scan results of the scanned file list of the sub-file, and at the same time update the first sub-modification timestamp of the F file in the first sub-file information to 9:30 and modify the first modification timestamp of the E directory to the recorded second modification timestamp of 10:00.

[0165] like Figure 12 The figure shows a schematic diagram of file scanning when the storage device is connected again. As shown in the figure, when the mobile hard disk is inserted into the smart screen again, the smart screen completes the file scan of the mobile hard disk, and the file scanning results of the scanned file list are updated in the smart screen database.

[0166] In actual testing of the present invention, to avoid the impact of file parsing, file parsing was separated from file scanning and placed in the process where parsing is actually required. Therefore, it can be understood that file parsing during actual testing is not time-consuming. The focus is on comparing the optimization effect of the file traversal process. The following example illustrates a specific test process and results.

[0167] Assume that the test uses a 4T mobile hard disk (i.e. storage device), which stores about 1,500 directories and about 30,000 files, with a total of about 2T of data. When the mobile hard disk is connected to an electronic device, it takes about 110 seconds for the electronic device to traverse all the files, and when no files are modified, the second traversal only takes about 6 seconds. When the modification ratio on the storage device reaches about 10%, the traversal takes about 21 seconds, and when the modification ratio reaches about 50%, the traversal time is about 57 seconds. It should be noted that all test data are the average results of multiple measurements, and the modification ratio is a comprehensive result based on the directory modification ratio and the file modification ratio.

[0168] From the above test results, by using the file scanning method of the embodiment of the present invention, when scanning the storage device again, the number of traversed files is reduced, thereby shortening the time for traversing files and improving the overall efficiency of file scanning.

[0169] The above describes in detail the method of the embodiment of the present invention. The following provides a related device of the embodiment of the present invention.

[0170] See Figure 13 , Figure 13 This is a structural diagram of a file scanning device provided by an embodiment of the present invention. The file scanning device 130 may include a receiving module 1301, a first acquisition module 1302, a second acquisition module 1303, a processing module 1304, a deletion module 1305, and a recording module 1306, wherein each unit is described in detail as follows.

[0171] Receiving module 1301, configured to receive a scan request for a target storage device;

[0172] A first acquisition module 1302 is configured to acquire first file information; the first file information includes first directory information of a scanned file list stored in the target storage device, the first directory information including a first modification timestamp of each directory in the scanned file list;

[0173] A second obtaining module 1303 is configured to obtain second file information, where the second file information includes second directory information of the to-be-scanned file list stored in the target storage device, and the second directory information includes a second modification timestamp of each directory in the to-be-scanned file list;

[0174] Processing module 1304 is used to compare the first directory information with the second directory information to generate a dirty directory set; the dirty directories in the dirty directory set are directories whose file names are the same as those in the first directory information and the second directory information and whose first modification timestamp is inconsistent with the second modification timestamp, or directories that appear in the second directory information but do not appear in the first directory information.

[0175] In a possible implementation, the first acquisition module 1302 is specifically configured to search for the first file information that matches a universally unique identifier (UUID) of the storage device according to the UUID.

[0176] In a possible implementation, the processing module 1304 is specifically configured to: if no directory exists in the first directory information, add the root directory of the to-be-scanned file list stored in the storage device to the dirty directory set.

[0177] In one possible implementation, the device also includes: a deletion module 1305, which is used to delete the directory to be deleted from the first directory information after comparing the first directory information with the second directory information, and delete the scanning results corresponding to the directory to be deleted; the directory to be deleted is a directory that appears in the first directory information and does not appear in the second directory information.

[0178] In a possible implementation, the processing module 1304 is specifically configured to: when the dirty directory set is an empty set, end the file scanning of the to-be-scanned file list.

[0179] In a possible implementation, the processing module 1304 is specifically configured to: when the dirty directory set is a non-empty set, perform file scanning on the dirty directories in the dirty directory set.

[0180] In one possible implementation, the processing module 1304 and the deletion module 1305 are specifically used: the processing module 1304 is used to compare the first modification timestamp with the second modification timestamp of the dirty directory in the dirty directory set; the deletion module 1305 is used to delete the dirty directory whose first modification timestamp is consistent with the second modification timestamp from the dirty directory set.

[0181] In a possible implementation, the apparatus further includes: a recording module 1306, configured to record attribute information of the dirty directory; the attribute information includes a second modification timestamp of the dirty directory.

[0182] In a possible implementation, the processing module 1304 is specifically configured to: traverse all direct sub-files under the dirty directory; the direct sub-files include sub-files and sub-directories under the dirty directory.

[0183] In one possible implementation, the first acquisition module 1302, the second acquisition module 1303 and the processing module 1304 are specifically used: the first acquisition module 1302 is used to obtain first sub-file information; the first sub-file information includes the first sub-modification timestamp of the direct sub-file of the dirty directory in the scanned file list; the second acquisition module 1303 is used to obtain second sub-file information; the second sub-file information includes the second modification timestamp of the direct sub-file of the dirty directory in the to-be-scanned file list; the processing module 1304 is used to compare the first sub-file information of the direct sub-file with the second sub-file information of the direct sub-file with the same file name to determine the modified direct sub-file.

[0184] In one possible implementation, the processing module 1304 is specifically used to: determine that the direct subfile is a modified direct subfile; the modified direct subfile is a direct subfile whose file name is the same as that in the first subfile information and the second subfile information and whose first sub-modification timestamp is inconsistent with that in the second sub-modification timestamp; determine that the direct subfile is a deleted direct subfile; the deleted direct subfile is a direct subfile that does not appear in the second subfile information and appears in the first subfile information.

[0185] In a possible implementation, the deleting module 1305 is specifically configured to delete the information of the deleted direct sub-files in the scanning result of the scanned file list.

[0186] In one possible implementation, the processing module 1304 is specifically used to: determine whether the modified direct subfile is a directory; if not, determine that the modified direct subfile is a modified subfile, obtain the file attributes of the modified subfile, perform file parsing on the modified subfile and update the scan result of the modified subfile in the scan result of the scanned file list; if so, determine that the modified direct subfile is a modified subdirectory, obtain the directory attributes of the modified subdirectory, set the first sub-modification timestamp of the modified subdirectory to a negative number, and insert the scan result of the modified subdirectory into the scan result of the scanned file list.

[0187] In one possible implementation, the processing module 1304 is specifically configured to:

[0188] Determine that all direct subfiles of the dirty directory have been traversed; update the current scan result of the dirty directory; the current scan result of the dirty directory includes a first modification timestamp of the dirty directory.

[0189] In one possible implementation, the processing module 1304 is specifically configured to: set the first modification timestamps of all scan results within the time period T3-ΔT to negative numbers; T3 is the time when the storage device uninstall message is received; and ΔT is a preset time period. It should be noted that the various functional modules in the file scanning device 130 described in the embodiment of the present invention can refer to the above Figure 6A and Figure 6B The description of steps S601 to S608 in the method embodiment will not be repeated here.

[0190] An embodiment of the present invention further provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, the program includes part or all of the steps of any one of the file scanning methods described in the above method embodiments.

[0191] An embodiment of the present invention further provides a computer program, which includes instructions. When the computer program is executed by a computer, the computer can execute part or all of the steps of any file scanning method.

[0192] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0193] It should be noted that for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps may be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily required by this application.

[0194] In the several embodiments provided in this application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the above-mentioned units is only a logical function division. In actual implementation, there may be other division methods, 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, and the indirect coupling or communication connection of devices or units can be electrical or other forms.

[0195] The units described above as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0196] In addition, the functional units in the embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0197] If the above-mentioned 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 technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server or a network device, etc., specifically a processor in a computer device) to execute all or part of the steps of the above-mentioned methods of each embodiment of the present application. Among them, the aforementioned storage medium may include: U disk, mobile hard disk, magnetic disk, optical disk, read-only memory (Read-Only Memory, abbreviated: ROM) or random access memory (Random Access Memory, abbreviated: RAM) and other media that can store program codes.

[0198] As described above, the above embodiments 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 above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or make equivalent replacements for some of the technical features therein. However, these 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.

Claims

1. A file scanning method, characterized in that: Used in electronic equipment, including: When a target storage device is connected to the electronic device, a scan request for the target storage device is received, and first file information is obtained; the first file information includes first directory information of a scanned file list stored when the target storage device was last connected to the electronic device, the first directory information including a file name of each directory in the scanned file list and a corresponding first modification timestamp; Obtaining second file information, where the second file information includes second directory information of a list of files to be scanned stored when the target storage device is reconnected to the electronic device, the second directory information including a file name of each directory in the list of files to be scanned and a corresponding second modification timestamp; Comparing the first directory information with the second directory information to generate a dirty directory set; dirty directories in the dirty directory set are directories whose file names are the same as those in the first directory information and the second directory information and whose first modification timestamps are inconsistent with those of the second modification timestamps, or directories that appear in the second directory information but not in the first directory information; The obtaining of the first file information includes: Searching for the first file information matching the universal unique identifier (UUID) of the target storage device according to the UUID; After comparing the first directory information with the second directory information, the method further includes: Deleting a directory to be deleted from the first directory information, and deleting a scan result corresponding to the directory to be deleted; the directory to be deleted is a directory that appears in the first directory information and does not appear in the second directory information; The method further comprises: All direct sub-files under the dirty directory are traversed; the direct sub-files include sub-files and sub-directories under the dirty directory.

2. The method according to claim 1, wherein Generating a dirty directory set includes: In a case where no directory exists in the first directory information, the root directory of the to-be-scanned file list stored in the target storage device is added to the dirty directory set.

3. The method according to claim 1, wherein The method further comprises: When the dirty directory set is an empty set, ending the file scanning of the to-be-scanned file list; When the dirty directory set is a non-empty set, file scanning is performed on the dirty directories in the dirty directory set.

4. The method according to claim 3, wherein Scanning files on the dirty directories in the dirty directory set includes: comparing the first modification timestamp and the second modification timestamp of the dirty directories in the dirty directory set; The dirty directory whose first modification timestamp is consistent with the second modification timestamp is deleted from the dirty directory set.

5. The method according to claim 1, wherein The method further comprises: Recording attribute information of the dirty directory; the attribute information includes a second modification timestamp of the dirty directory.

6. The method according to claim 1, wherein The method further comprises: Obtaining first sub-file information; the first sub-file information includes a first sub-modification timestamp of the direct sub-file of the dirty directory in the scanned file list; Acquire second sub-file information; the second sub-file information includes a second sub-modification timestamp of the direct sub-file of the dirty directory in the list of files to be scanned; The first sub-file information and the second sub-file information of the direct sub-files with the same file name are compared to determine the modified direct sub-file.

7. The method according to claim 6, wherein The determining the modified direct sub-file includes: Determining that the direct child file is a modified direct child file; the modified direct child file is a direct child file whose file name is the same as that in the first child file information and the second child file information, and whose first child modification timestamp is inconsistent with that in the second child modification timestamp; The direct subfile is determined to be a deleted direct subfile; the deleted direct subfile is a direct subfile that does not appear in the second subfile information but appears in the first subfile information.

8. The method according to claim 7, wherein: The method further comprises: The information of the deleted direct sub-files in the scanning result of the scanned file list is deleted.

9. The method according to claim 7, wherein: The method further comprises: Determine whether the modified direct child file is a directory; If not, determining that the modified direct subfile is a modified subfile, obtaining file attributes of the modified subfile, performing file parsing on the modified subfile, and updating the scan result of the modified subfile in the scan result of the scanned file list; If so, determine that the modified direct sub-file is a modified sub-directory, obtain the directory attributes of the modified sub-directory, set the first sub-modification timestamp of the modified sub-directory to a negative number, and insert the scanning result of the modified sub-directory into the scanning result of the scanned file list.

10. The method of claim 9, wherein inserting the scan result of the modified subdirectory into the scan result of the scanned file list comprises: Determining whether the scan result of the modified subdirectory is successfully inserted into the scan result of the scanned file list; If the insertion is successful, the modified subdirectory is added to the dirty directory set.

11. The method according to any one of claims 1 to 10, wherein: The method further comprises: Determine that all the direct subfiles of the dirty directory have been traversed; The scanning result of the current dirty directory is updated; the scanning result of the current dirty directory includes the first modification timestamp of the dirty directory.

12. The method according to claim 1, wherein The method further comprises: The first modification timestamps of the directories in all scan results within the time period T3-ΔT are set to negative numbers; T3 is the time when the target storage device uninstallation message is received; and ΔT is a preset time period.

13. A document scanning device, characterized in that: Used in electronic equipment, including: a receiving module, configured to receive a scan request for a target storage device when the target storage device is connected to the electronic device; a first acquisition module, configured to acquire first file information; the first file information comprising first directory information of a scanned file list stored when the target storage device was last connected to the electronic device, the first directory information comprising a file name of each directory in the scanned file list and a corresponding first modification timestamp; a second acquisition module, configured to acquire second file information, the second file information including second directory information of the list of files to be scanned stored when the target storage device is reconnected to the electronic device, the second directory information including the file name of each directory in the list of files to be scanned and a corresponding second modification timestamp; a processing module, configured to compare the first directory information with the second directory information to generate a dirty directory set; a dirty directory in the dirty directory set is a directory having the same file name in the first directory information and the second directory information and an inconsistent first modification timestamp and the second modification timestamp, or a directory that appears in the second directory information but does not appear in the first directory information; The first acquisition module is specifically configured to: Searching for the first file information matching the universal unique identifier (UUID) of the target storage device according to the UUID; The device further comprises: a deleting module configured to delete a directory to be deleted from the first directory information after comparing the first directory information with the second directory information, and to delete a scan result corresponding to the directory to be deleted; the directory to be deleted is a directory that appears in the first directory information but does not appear in the second directory information; The processing module is further configured to: All direct sub-files under the dirty directory are traversed; the direct sub-files include sub-files and sub-directories under the dirty directory.

14. The device according to claim 13, wherein The processing module is further configured to: When the dirty directory set is an empty set, ending the file scanning of the to-be-scanned file list; When the dirty directory set is a non-empty set, file scanning is performed on the dirty directories in the dirty directory set.

15. The device according to claim 14, wherein The processing module is specifically configured to compare the first modification timestamp and the second modification timestamp of the dirty directories in the dirty directory set; The deleting module is specifically configured to delete a dirty directory whose first modification timestamp is consistent with the second modification timestamp from the dirty directory set.

16. The device according to claim 13, wherein The device further comprises: The recording module is configured to record attribute information of the dirty directory; the attribute information includes a second modification timestamp of the dirty directory.

17. The device according to claim 13, wherein The first acquisition module is further configured to acquire first sub-file information; the first sub-file information includes a first sub-modification timestamp of the direct sub-file of the dirty directory in the scanned file list; The second acquisition module is further configured to acquire second sub-file information; the second sub-file information includes a second sub-modification timestamp of the direct sub-file of the dirty directory in the list of files to be scanned; The processing module is further configured to compare the first sub-file information and the second sub-file information of the direct sub-files with the same file name to determine the modified direct sub-file.

18. The device according to claim 17, wherein The processing module is specifically used to: Determining that the direct child file is a modified direct child file; the modified direct child file is a direct child file whose file name is the same as that in the first child file information and the second child file information, and whose first child modification timestamp is inconsistent with that in the second child modification timestamp; Determining that the direct child file is a deleted direct child file; The deleted direct subfile is a direct subfile that does not appear in the second subfile information but appears in the first subfile information.

19. The device according to claim 18, characterized in that The processing module is further configured to: Determine whether the modified direct child file is a directory; If not, determining that the modified direct subfile is a modified subfile, obtaining file attributes of the modified subfile, performing file parsing on the modified subfile, and updating the scan result of the modified subfile in the scan result of the scanned file list; If so, determine that the modified direct sub-file is a modified sub-directory, obtain the directory attributes of the modified sub-directory, set the first sub-modification timestamp of the modified sub-directory to a negative number, and insert the scanning result of the modified sub-directory into the scanning result of the scanned file list.

20. The apparatus according to claim 19, wherein the processing module is specifically configured to: Determining whether the scan result of the modified subdirectory is successfully inserted into the scan result of the scanned file list; If the insertion is successful, the modified subdirectory is added to the dirty directory set.

21. The apparatus according to any one of claims 13 to 20, wherein the processing module is further configured to: Determine that all the direct subfiles of the dirty directory have been traversed; The scanning result of the current dirty directory is updated; the scanning result of the current dirty directory includes the first modification timestamp of the dirty directory.

22. A computer storage medium, characterized in that The computer storage medium stores a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 12.

23. A computer program, characterized in that The computer program comprises instructions, and when the computer program is executed by a computer, the computer is caused to perform the method according to any one of claims 1 to 12.

Citation Information

Patent Citations

  • Scanning method and device for storage space in mobile terminal

    CN104317952A