A method and system for scanning documents

By managing the database according to the ID of the storage device in the vehicle computer system, the problems of long time, low speed and low efficiency when scanning files in the prior art are solved, and a faster and more efficient file scanning process is achieved.

CN113111052BActive Publication Date: 2025-06-13BEIJING SIWEI ZHILIAN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202010026568.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-01-10
Publication Date
2025-06-13
Estimated Expiration
2040-01-10

AI Technical Summary

Technical Problem

When scanning storage device files, existing vehicle computer systems need to clear the database and re-scan the entire disk every time the storage device is unplugged, resulting in long scanning time, low speed and low efficiency.

Method used

By determining whether the corresponding database exists based on the ID of the storage device, if it exists, delete inconsistent files and insert new files in batches; if it does not exist, create a database and insert files in batches. Transaction processing is used to batch insert multiple files into the database to reduce the number of database operations.

Benefits of technology

Reduces scanning time, improves scanning speed and efficiency, and avoids the long scanning process every time the storage device is unplugged.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113111052B_ABST
    Figure CN113111052B_ABST
Patent Text Reader

Abstract

The present invention provides a method and system for scanning files. According to the ID of a storage device, it is determined whether there is a corresponding database; if there is, the files in the database that are inconsistent with the files in the storage device are deleted; the storage device is scanned to obtain multiple new files that do not exist in the database, and the multiple new files are batch inserted into the database; if there is no database, a database is created; the storage device is scanned, and multiple files in the storage device obtained by scanning are batch inserted into the database. In this solution, it is determined whether there is a database corresponding to the storage device. If there is, the files in the database that are inconsistent with the files in the storage device are deleted, and the new files are batch stored in the database. If not, a database is created, and multiple files in the storage device are batch inserted into the database. It is not necessary to clear the database every time the storage device is plugged in or unplugged, and the batch storage method is adopted when storing files, which reduces the scanning time and improves the scanning speed and efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data processing, and in particular, to a method and system for scanning files. Background Art

[0002] With the development of electronic technology, the degree of electronicization of automobiles is also getting higher and higher, and many automobiles are equipped with in-vehicle systems.

[0003] When a user inserts a storage device through the USB interface of the in-vehicle system, the in-vehicle system scans and plays the multimedia files in the storage device. Currently, the way the in-vehicle system scans the files in the storage device is as follows: every time the storage device is plugged in and unplugged through the USB interface of the in-vehicle system, the database needs to be cleared and the entire storage device needs to be scanned again, and the database is operated once for each piece of data scanned. However, every time the storage device is plugged in and unplugged, the entire storage device needs to be scanned again, and the database is operated once for each piece of data scanned, which requires a long scanning time, low scanning speed, and low scanning efficiency. Summary of the Invention

[0004] In view of this, embodiments of the present invention provide a method and system for scanning files to solve the problems such as long scanning time, low scanning speed, and low scanning efficiency existing in the existing file scanning method.

[0005] To achieve the above object, embodiments of the present invention provide the following technical solutions:

[0006] A first aspect of an embodiment of the present invention discloses a method for scanning files, the method including:

[0007] Determine whether there is a database corresponding to the ID according to the ID of the storage device;

[0008] If the database exists, delete the files in the database that are inconsistent with the files in the storage device;

[0009] Scan the storage device, obtain a plurality of new files that do not exist in the database, and batch insert the plurality of new files into the database;

[0010] If the database does not exist, create the database;

[0011] Scan the storage device, and batch insert the plurality of files in the storage device obtained by scanning into the database.

[0012] Preferably, the deleting the files in the database that are inconsistent with the files in the storage device includes:

[0013] Scan the files in the database;

[0014] For each file scanned from the database, determine whether the file exists in the storage device;

[0015] If the file does not exist in the storage device, delete the file.

[0016] Preferably, scanning the storage device to obtain multiple new files that do not exist in the database, and batch inserting the multiple new files into the database includes:

[0017] Scan the storage device to obtain new files that do not exist in the database;

[0018] Store the new files in the cache;

[0019] Determine whether the scanning of the storage device is completed;

[0020] If the scanning of the storage device is completed, use transaction processing to batch insert one or more of the new files in the cache into the database;

[0021] If the scanning of the storage device is not completed, return to execute the step of scanning the storage device.

[0022] Preferably, scanning the storage device to obtain multiple new files that do not exist in the database, and batch inserting the multiple new files into the database includes:

[0023] Scan the storage device to obtain new files that do not exist in the database;

[0024] Store the new files in the cache;

[0025] Determine whether the scanning of the storage device is completed;

[0026] If the scanning of the storage device is completed, use transaction processing to batch insert one or more of the new files in the cache into the database;

[0027] If the scanning of the storage device is not completed, determine whether the number of the new files in the cache is equal to the number threshold;

[0028] If the number of the new files in the cache is less than the number threshold, return to execute the step of scanning the storage device;

[0029] If the number of the new files in the cache is equal to the number threshold, use transaction processing to batch insert all the new files in the cache into the database, and return to execute the step of scanning the storage device.

[0030] Preferably, scanning the storage device and batch inserting multiple files in the storage device obtained by scanning into the database includes:

[0031] Scanning the storage device to obtain the files of the storage device;

[0032] Determining whether the files of the storage device exist in the database;

[0033] If the files of the storage device exist in the database, return to execute the step of scanning the storage device;

[0034] If the files of the storage device do not exist in the database, storing the files of the storage device in a cache;

[0035] Judging whether the scanning of the storage device is completed;

[0036] If the scanning of the storage device is completed, using transaction processing to batch insert one or more of the files in the cache into the database;

[0037] If the scanning of the storage device is not completed, return to execute the step of scanning the storage device.

[0038] Preferably, scanning the storage device and batch inserting multiple files in the storage device obtained by scanning into the database includes:

[0039] Scanning the storage device to obtain the files of the storage device;

[0040] Determining whether the files of the storage device exist in the database;

[0041] If the files of the storage device exist in the database, return to execute the step of scanning the storage device;

[0042] If the files of the storage device do not exist in the database, storing the files of the storage device in a cache;

[0043] Judging whether the scanning of the storage device is completed;

[0044] If the scanning of the storage device is completed, using transaction processing to batch insert one or more files in the cache into the database;

[0045] If the scanning of the storage device is not completed, determining whether the number of files in the cache is equal to a number threshold;

[0046] If the number of files in the cache is less than the number threshold, return to execute the step of scanning the storage device;

[0047] If the number of files in the cache is equal to the number threshold, use transaction processing to batch insert all the files in the cache into the database, and return to the step of scanning the storage device.

[0048] Preferably, scanning the storage device to obtain multiple new files that do not exist in the database and batch inserting the multiple new files into the database includes:

[0049] Scanning the storage device at the C++ layer according to JNI to obtain multiple new files that do not exist in the database, and batch inserting the multiple new files into the database at the JAVA layer through JNI;

[0050] Correspondingly, scanning the storage device and batch inserting multiple files in the storage device obtained by scanning into the database includes:

[0051] Scanning the storage device at the C++ layer according to JNI, and batch inserting multiple files in the storage device obtained by scanning into the database at the JAVA layer through JNI.

[0052] Preferably, before determining whether there is a database corresponding to the ID according to the ID of the storage device, it further includes:

[0053] Using NetlinkEvent to add the ID of the storage device;

[0054] Mounting the storage device.

[0055] A second aspect of the embodiments of the present invention discloses a system for scanning files, and the system includes:

[0056] A determination unit, configured to determine whether there is a database corresponding to the ID according to the ID of the storage device. If the database exists, execute the deletion unit; if the database does not exist, execute the creation unit;

[0057] The deletion unit is configured to delete the files in the database that are inconsistent with the files in the storage device, and execute the first scanning unit;

[0058] The first scanning unit is configured to scan the storage device to obtain multiple new files that do not exist in the database, and batch insert the multiple new files into the database;

[0059] The creation unit is configured to create the database and execute the second scanning unit;

[0060] The second scanning unit is configured to scan the storage device and batch insert multiple files in the storage device obtained by scanning into the database.

[0061] Preferably, the deletion unit is specifically configured to: scan the files in the database, and for each file scanned from the database, determine whether the file exists in the storage device. If the file does not exist in the storage device, delete the file.

[0062] Based on the method and system for scanning files provided in the above embodiments of the present invention, the method is as follows: determine whether there is a database corresponding to the ID according to the ID of the storage device; if so, delete the files in the database that are inconsistent with the files in the storage device; scan the storage device, obtain multiple new files that do not exist in the database, and batch insert the multiple new files into the database; if there is no database, create a database; scan the storage device, and batch insert the multiple files scanned from the storage device into the database. In this solution, it is determined whether there is a database corresponding to the storage device. If so, delete the files in the database that are inconsistent with the files in the storage device, and batch store the new files in the database. If not, create a database and batch insert the multiple files in the storage device into the database. It is not necessary to clear the database every time the storage device is plugged in or unplugged, and the batch storage method is adopted when storing files, which reduces the scanning time and improves the scanning speed and efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained according to the provided drawings without creative efforts.

[0064] Figure 1 It is a flowchart of a method for scanning files provided by an embodiment of the present invention;

[0065] Figure 2 It is an architecture diagram of a system for scanning files provided by an embodiment of the present invention;

[0066] Figure 3 It is a flowchart of batch inserting new files into the database provided by an embodiment of the present invention;

[0067] Figure 4 It is another flowchart of batch inserting new files into the database provided by an embodiment of the present invention;

[0068] Figure 5 It is a flowchart of batch inserting multiple files into the database provided by an embodiment of the present invention;

[0069] Figure 6 It is another flowchart of batch inserting multiple files into the database provided by an embodiment of the present invention;

[0070] Figure 7 Another flowchart of the method for scanning files provided by the embodiments of the present invention;

[0071] Figure 8 Flowchart for scanning new files in a USB flash drive provided by the embodiments of the present invention;

[0072] Figure 9 Flowchart for scanning files in a USB flash drive provided by the embodiments of the present invention;

[0073] Figure 10 Block diagram of the structure of a file scanning system provided by the embodiments of the present invention. Detailed implementation manners

[0074] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0075] In this application, the term "including", "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements but also includes other elements not explicitly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "including one..." does not exclude the existence of additional identical elements in the process, method, article or device including the said element.

[0076] As can be seen from the background technology, currently, the way for the in-vehicle infotainment system to scan files in a storage device is as follows: every time a storage device is plugged in or unplugged, the database needs to be cleared and the entire storage device needs to be scanned again, and the database is operated once for each piece of data scanned. Re-scanning the entire storage device every time a storage device is plugged in or unplugged, and operating the database once for each piece of data scanned, requires a long scanning time, low scanning speed and low scanning efficiency.

[0077] Therefore, the embodiments of the present invention provide a method and a system for scanning files. When a storage device is inserted into the in-vehicle infotainment system, it is determined whether there is a database corresponding to the storage device. If it exists, the files in the database that are inconsistent with the files in the storage device are deleted, and the new files are batch-stored in the database. If it does not exist, a database is created, and multiple files in the storage device are batch-inserted into the database. That is to say, it is not necessary to clear the database every time a storage device is plugged in or unplugged, and at the same time, a batch-storage method is adopted when storing files, so as to reduce the scanning time, improve the scanning speed and improve the scanning efficiency.

[0078] See Figure 1 , which shows a flowchart of a method for scanning files provided by an embodiment of the present invention. The method includes:

[0079] Step S101: Determine whether there is a database corresponding to the ID according to the ID of the storage device. If there is a database corresponding to the ID, execute step S102. If there is no database corresponding to the ID, execute step S104.

[0080] Preferably, before executing step S101, when it is detected that the storage device is inserted into the vehicle system, use NetlinkEvent to add the ID of the storage device and mount the storage device.

[0081] In the process of specifically implementing step S101, obtain the ID of the storage device and determine whether there is a database corresponding to the ID. If there is a database corresponding to the ID, switch to the database for subsequent corresponding operations. If there is no database corresponding to the ID, create a database.

[0082] It should be noted that the ID of a storage device corresponds to a database, and the types of storage devices include but are not limited to storage devices with storage functions such as USB flash drives and hard disks.

[0083] It can be understood that in the embodiment of the present invention, it is not necessary to completely clear the database every time the storage device is plugged in or unplugged.

[0084] Step S102: Delete the files in the database that are inconsistent with the files in the storage device.

[0085] In the process of specifically implementing step S102, scan the files in the database. For each file obtained by scanning the database, determine whether the file exists in the storage device. If the file does not exist in the storage device, delete the file. That is to say, delete the files that only exist in the database but not in the storage device.

[0086] Step S103: Scan the storage device, obtain multiple new files that do not exist in the database, and batch insert the multiple new files into the database.

[0087] In the specific implementation process, scan the storage device according to JNI at the C++ layer, obtain multiple new files that do not exist in the database, and batch insert the multiple new files into the database through JNI at the JAVA layer. That is to say, call the code at the C++ layer through JNI to scan the storage device. After the scanning is completed, return the scanning result to the code at the JAVA layer through JNI, and batch insert the multiple new files into the database at the JAVA layer.

[0088] It can be understood that in step S102, the files that only exist in the database but not in the storage device are deleted. There may be multiple new files in the storage device that do not exist in the database, so multiple new files in the storage device need to be batch stored in the database.

[0089] Step S104: Create a database.

[0090] In the specific implementation process of step S104, if the database corresponding to the ID of the storage device is not queried, the database corresponding to the ID is created.

[0091] Step S105: Scan the storage device and batch insert multiple files in the scanned storage device into the database.

[0092] In the specific implementation process of step S105, the storage device is scanned at the C++ layer according to JNI, and multiple files in the scanned storage device are batch inserted into the database at the JAVA layer through JNI. The process of scanning the storage device and inserting multiple files into the database can refer to the content in step S103 above.

[0093] It should be noted that the existing method of scanning the storage device is to scan at the JAVA layer. Combining the content in step S103 and step S105 above, the method of scanning the storage device in the embodiment of the present invention is to scan at the C++ layer. The time required to scan the storage device at the C++ layer is lower than that at the JAVA layer.

[0094] For example: For a storage device, the storage device has 30 folders, has three levels of directories, and stores a total of 2000 files. The time required to scan the storage device at the JAVA layer is 1206 ms, while the time required to scan the storage device at the C++ layer is 356 ms.

[0095] To better explain the principle of scanning the storage device at the C++ layer involved above, through Figure 2 the shown system architecture diagram of scanning files is used for illustration. It should be noted that Figure 2 it is only for illustration.

[0096] In Figure 2 it, the Kenel layer at least includes a USB driver.

[0097] The Native (C++) layer at least includes MediaScanner and NetlinkEvent involved in step S101 above.

[0098] The JAVA layer at least includes: MediaProvider, DatabaseHelper, HashMap, and MediaScannerService.

[0099] It should be noted that MediaProvider uses the information of multimedia files such as pictures, videos, and audios stored in the database for use by video players, music players, etc.

[0100] DatabaseHelper is used to manage the creation and version update of data.

[0101] MediaScannerService is a service for scanning multimedia files and at least includes services such as prescan, scan, and postscan.

[0102] HashMap at least includes information about multiple USBs.

[0103] In the embodiment of the present invention, when detecting the insertion of a storage device, it is determined whether there is a database corresponding to the storage device according to the ID of the storage device. If it exists, the files inconsistent with the files in the storage device in the database are deleted, and the new files are batch - stored in the database. If it does not exist, a database is created, and multiple files in the storage device are batch - inserted into the database. There is no need to clear the database every time the storage device is plugged or unplugged, and the batch - storage method is adopted when storing files, which reduces the scanning time and improves the scanning speed and efficiency.

[0104] The above - mentioned embodiment of the present invention Figure 1 For the process of batch - inserting multiple new files into the database involved in step S103, refer to Figure 3 , which shows the flowchart of batch - inserting new files into the database provided by the embodiment of the present invention, including the following steps:

[0105] Step S301: Scan the storage device to obtain new files that do not exist in the database.

[0106] In the specific implementation process of step S301, scan the files in the storage device to obtain new files that exist in the storage device but do not exist in the database.

[0107] Step S302: Store the new files in the cache.

[0108] In the specific implementation process of step S302, store the scanned new files in the cache.

[0109] Step S303: Determine whether the scanning of the storage device is completed. If the scanning of the storage device is completed, execute step S304. If the scanning of the storage device is not completed, return to execute step S301.

[0110] In the process of specifically implementing step S303, if the scanning of the storage device is completed, one or more new files in the cache are inserted into the database. If the scanning of the storage device is not completed, return to execute step S301 to continue scanning the storage device, that is, continue to scan other files in the storage device.

[0111] Step S304: Using transaction processing, batch insert one or more new files in the cache into the database.

[0112] In the process of specifically implementing step S304, when inserting the new files in the cache into the database, one or more new files in the cache are batch inserted into the database in the way of transaction processing. Correspondingly, other ways of batch inserting into the database can also be used to batch insert one or more new files in the cache into the database.

[0113] It should be noted that transaction processing means inserting all the new files in the cache into the database to reduce the time for storing the new files into the database. The specific ways of calling transaction processing include but are not limited to: calling the beginTransaction() method of SQLiteDatabase to start a transaction, executing the corresponding database insert operation in the code block of exception capture to insert all the new files in the cache into the database. When the operation on this database is completed, call setTransactionSuccessful() to indicate that the transaction has been executed successfully, and finally call endTransaction() to end the transaction.

[0114] As can be seen from the background art, the existing way of inserting the read files into the database is to execute the database insert operation once for each read file. In the embodiment of the present invention, the read files are stored in the cache, and then all the files in the cache are inserted into the database by using transaction processing, which not only reduces the scanning time but also improves the scanning efficiency.

[0115] For example: Suppose 1000 files are scanned. The existing way takes a total of 14002 ms to insert 1000 files into the database. Using the transaction processing involved in the embodiment of the present invention, it takes 1011 ms to insert 1000 files into the database.

[0116] In the embodiment of the present invention, scan the storage device, obtain the new files that do not exist in the database, and store the new files in the cache. After the scanning of the storage device is completed, use transaction processing to insert all the new files in the cache into the database, reducing the scanning time and improving the scanning efficiency.

[0117] The above embodiments of the present invention Figure 1For the process of batch inserting multiple new files into the database involved in step S103, refer to Figure 4 , which shows another flowchart for batch inserting new files into the database provided by an embodiment of the present invention, including the following steps:

[0118] Step S401: Scan the storage device to obtain new files that do not exist in the database.

[0119] Step S402: Store the new files in the cache.

[0120] Step S403: Determine whether the scanning of the storage device is completed. If the scanning of the storage device is completed, execute step S404. If the scanning of the storage device is not completed, execute step S405.

[0121] In the specific implementation of step S404, if the scanning of the storage device is completed, use transaction processing to batch insert more than one new file in the cache into the database. For the specific process of inserting into the database, refer to the content of step S304 in the above embodiment of the present invention. Figure 3 The content of step S304.

[0122] If the scanning of the storage device is not completed, determine whether the number of new files in the cache is equal to the number threshold. When the number of new files in the cache is equal to the number threshold, use transaction processing to batch insert all new files in the cache into the database. That is, even if the scanning of the storage device is not completed, but the number of new files in the cache reaches the number threshold, all new files in the cache are also inserted into the database using transaction processing.

[0123] For example: If the scanning of the storage device is not completed, and the number of new files in the cache is equal to 500, use transaction processing to insert 500 new files in the cache into the database.

[0124] Step S404: Use transaction processing to batch insert more than one new file in the cache into the database.

[0125] Step S405: Determine whether the number of new files in the cache is equal to the number threshold. If the number of new files in the cache is less than the number threshold, return to execute step S401. If the number of new files in the cache is equal to the number threshold, execute step S406.

[0126] In the specific implementation of step S405, if the scanning of the storage device is not completed and the number of new files in the cache is less than the number threshold, return to execute step S401 to continue scanning the storage device. If the number of new files in the cache is equal to the number threshold, use transaction processing to batch insert all new files in the cache into the database, and then return to execute step S401 to continue scanning the storage device.

[0127] Step S406: Use transaction processing to batch insert all new files in the cache into the database, and return to execute Step S401.

[0128] In the embodiment of the present invention, the storage device is scanned to obtain new files that do not exist in the database, and the new files are stored in the cache. After the scanning of the storage device is completed, the new files in the cache are inserted into the database using transaction processing. When the scanning of the storage device is not completed, but the number of new files in the cache is equal to the number threshold, the new files in the cache are inserted into the database using transaction processing. The scanning time is reduced and the scanning efficiency is improved.

[0129] The above embodiment of the present invention Figure 1 For the process of batch inserting multiple files into the database involved in Step S105, refer to Figure 5 , which shows the flowchart of batch inserting multiple files into the database provided by the embodiment of the present invention, including the following steps:

[0130] Step S501: Scan the storage device to obtain the files of the storage device.

[0131] In the process of specifically implementing Step S501, after creating the database, the files in the storage device need to be inserted into the database. Therefore, the storage device is scanned to obtain the files of the storage device.

[0132] Step S502: Determine whether the files of the storage device exist in the database. If the files of the storage device exist in the database, return to execute Step S501. If the files of the storage device do not exist in the database, execute Step S503.

[0133] In the process of specifically implementing Step S502, in the specific application process, multiple scanning processes may occur. To avoid inserting files into the database repeatedly, whenever a file is scanned, it is necessary to determine whether the file already exists in the database. If the file already exists in the database, return to execute Step S501 to continue scanning the storage device. If the file does not exist in the database, store the file in the cache.

[0134] Step S503: Store the files of the storage device in the cache.

[0135] Step S504: Determine whether the scanning of the storage device is completed. If the scanning of the storage device is completed, execute Step S505. If the scanning of the storage device is not completed, return to execute Step S501.

[0136] In the process of specifically implementing Step S504, if the scanning of the storage device is completed, one or more files in the cache are inserted into the database. If the scanning of the storage device is not completed, return to execute Step S501 to continue scanning the storage device.

[0137] Step S505: Use transaction processing to batch insert more than one file in the cache into the database.

[0138] In the specific implementation of step S505, for the process of using transaction processing to batch insert more than one file in the cache into the database, refer to the above embodiments of the present invention Figure 3 the content in step S304 will not be elaborated here.

[0139] In the embodiments of the present invention, after creating the database corresponding to the storage device, scan the files in the storage device. If the scanned file does not exist in the database, store the file in the cache. After completing the scan of the storage device, use transaction processing to batch insert the files in the cache into the database. This reduces the scan time and improves the scan efficiency.

[0140] the above embodiments of the present invention Figure 1 For the process of batch inserting multiple files into the database involved in step S105, refer to Figure 6 , which shows another flowchart for batch inserting multiple files into the database provided by the embodiments of the present invention, including the following steps:

[0141] Step S601: Scan the storage device to obtain the files in the storage device.

[0142] Step S602: Determine whether the files in the storage device exist in the database. If the files in the storage device exist in the database, return to execute step S601. If the files in the storage device do not exist in the database, execute step S603.

[0143] In the specific application process, multiple scan processes may occur. To avoid inserting files into the database repeatedly, whenever a file is scanned, it is necessary to determine whether the file already exists in the database. If the file already exists in the database, return to execute step S601 to continue scanning the storage device. If the file does not exist in the database, store the file in the cache.

[0144] Step S603: Store the files in the storage device in the cache.

[0145] Step S604: Determine whether the scan of the storage device is completed. If the scan of the storage device is completed, execute step S605. If the scan of the storage device is not completed, execute step S606.

[0146] In the specific implementation of step S604, if the scan of the storage device is completed, insert more than one file in the cache into the database. If the scan of the storage device is not completed, determine whether the number of files in the cache is equal to the number threshold. If the number of files in the cache is equal to the number threshold, use transaction processing to batch insert all the files in the cache into the database.

[0147] For example, if the scanning of the storage device is not completed and the number of files in the cache is equal to 500, 500 files in the cache are inserted into the database using transaction processing.

[0148] Step S605: Use transaction processing to batch insert more than one file in the cache into the database.

[0149] For the process of using transaction processing to batch insert more than one file in the cache into the database, refer to the content of the embodiment of the present invention above Figure 3 in step S304, which will not be elaborated here.

[0150] Step S606: Determine whether the number of files in the cache is equal to the number threshold. If the number of files in the cache is less than the number threshold, return to execute step S601. If the number of files in the cache is equal to the number threshold, execute step S607.

[0151] In the process of specifically implementing step S606, if the scanning of the storage device is not completed and the number of files in the cache is less than the number threshold, return to execute step S601 to continue scanning the storage device. If the number of files in the cache is equal to the number threshold, use transaction processing to batch insert all files in the cache into the database, and return to execute step S601 to continue scanning the storage device.

[0152] Step S607: Use transaction processing to batch insert all files in the cache into the database, and return to execute step S601.

[0153] In the embodiment of the present invention, after creating the database corresponding to the storage device, scan the files in the storage device. If the scanned files do not exist in the database, store the files in the cache. After completing the scanning of the storage device, use transaction processing to batch insert the files in the cache into the database. When the scanning of the storage device is not completed, but the number of files in the cache is equal to the number threshold, use transaction processing to batch insert the files in the cache into the database. This reduces the scanning time and improves the scanning efficiency.

[0154] For better explanation of the above embodiments of the present invention Figure 1 , and Figures 3 to 6 the content involved in each step in Figures 7 to 9 , an example is given through Figures 7 to 9 . It should be noted that

[0155] Refer to Figure 7 , which shows another flowchart of the method for scanning files provided by the embodiment of the present invention, including the following steps:

[0156] Step S701: Detect the insertion of a USB flash drive.

[0157] Step S702: Use NetlinkEvent to add the ID of the USB flash drive.

[0158] Step S703: Mount the USB flash drive.

[0159] Step S704: Determine whether there is a database corresponding to the ID according to the ID of the USB flash drive. If there is a database corresponding to the ID, execute Step S705; if there is no database corresponding to the ID, execute Step S706.

[0160] Step S705: Delete the files in the database that are inconsistent with the files in the USB flash drive, and scan the new files in the USB flash drive, as Figure 8 shown.

[0161] Step S706: Create a database and scan the files in the USB flash drive, as Figure 9 shown.

[0162] It should be noted that for the execution principles of the above Steps S701 to S706, reference can be made to the relevant content of each step in the above embodiments of the present invention Figure 1 , and Figures 3 to 6 involved in each step.

[0163] See Figure 8 , which shows the flowchart for scanning new files in the USB flash drive provided by the embodiments of the present invention, including the following steps:

[0164] Step S801: Scan the database to obtain database files.

[0165] Step S802: Determine whether the database file exists in the USB flash drive. If the database file exists in the USB flash drive, execute Step S804; if the database file does not exist in the USB flash drive, execute Step S803.

[0166] Step S803: Delete the database file and execute Step S804.

[0167] Step S804: Determine whether the database scan is completed. If the database scan is not completed, return to execute Step S801; if the database scan is completed, execute Step S805.

[0168] Step S805: Scan the USB flash drive to obtain new files that exist in the USB flash drive but do not exist in the database.

[0169] Step S806: Insert the scanned new files into the database.

[0170] In the specific process of implementing Step S806, for the method of inserting the scanned new files into the database, reference can be made to the above embodiments of the present invention Figure 3 andFigure 4 The content shown will not be elaborated here.

[0171] It should be noted that for the implementation principles of the above steps S801 to S806, reference can be made to the relevant content in the above embodiments of the present invention Figure 1 , Figure 3 and Figure 4 the content involved in each step in

[0172] Refer to Figure 9 , which shows the flowchart of scanning the files of a USB flash drive provided by the embodiments of the present invention, including the following steps:

[0173] Step S901: Scan the USB flash drive to obtain the files on the USB flash drive.

[0174] Step S902: Determine whether the files on the USB flash drive exist in the database. If the files on the USB flash drive exist in the database, return to execute Step S901. If the files on the USB flash drive do not exist in the database, execute Step S903.

[0175] Step S903: Store the files on the USB flash drive in the cache.

[0176] Step S904: Insert the files in the cache into the database.

[0177] In the specific process of implementing Step S904, for the method of inserting the files in the cache into the database, reference can be made to the relevant content shown in the above embodiments of the present invention Figure 5 and Figure 6 will not be elaborated here.

[0178] It should be noted that for the implementation principles of the above steps S901 to S904, reference can be made to the relevant content in the above embodiments of the present invention Figure 1 , Figure 5 and Figure 6 the content involved in each step in

[0179] In the embodiments of the present invention, when detecting the insertion of a USB flash drive, it is determined whether there is a corresponding database according to the ID of the USB flash drive. If it exists, delete the files in the database that are inconsistent with the files on the USB flash drive, and batch-store the new files in the database. If it does not exist, create a database and batch-insert multiple files on the USB flash drive into the database. There is no need to clear the database every time the USB flash drive is plugged in or unplugged, and the batch-storing method is adopted when storing files, which reduces the scanning time and improves the scanning speed and efficiency.

[0180] Corresponding to the method for scanning files provided by the above embodiments of the present invention, refer to Figure 10, an embodiment of the present invention also provides a structural block diagram of a system for scanning files. The system includes: a determination unit 1001, a deletion unit 1002, a first scanning unit 1003, a creation unit 1004, and a second scanning unit 1005;

[0181] The determination unit 1001 is configured to determine whether there is a database corresponding to the ID according to the ID of the storage device. If there is a database, execute the deletion unit 1002. If there is no database, execute the creation unit 1004.

[0182] The deletion unit 1002 is configured to delete the files in the database that are inconsistent with the files in the storage device, and then execute the first scanning unit 1003.

[0183] In a specific implementation, the deletion unit 1002 is specifically configured to: scan the files in the database, and for each file obtained by scanning in the database, determine whether the file exists in the storage device. If the file does not exist in the storage device, delete the file.

[0184] The first scanning unit 1003 is configured to scan the storage device, obtain multiple new files that do not exist in the database, and batch insert the multiple new files into the database.

[0185] In a specific implementation, the first scanning unit 1003 is specifically configured to: scan the storage device according to JNI at the C++ layer, obtain multiple new files that do not exist in the database, and batch insert the multiple new files into the database through JNI at the JAVA layer.

[0186] The creation unit 1004 is configured to create a database, and then execute the second scanning unit 1005.

[0187] The second scanning unit 1005 is configured to scan the storage device, and batch insert the multiple files obtained by scanning in the storage device into the database.

[0188] In a specific implementation, the second scanning unit 1005 is specifically configured to: scan the storage device according to JNI at the C++ layer, and batch insert the multiple files obtained by scanning in the storage device into the database through JNI at the JAVA layer.

[0189] In an embodiment of the present invention, when detecting the insertion of a storage device, it is determined whether there is a database corresponding to the storage device according to the ID of the storage device. If there is, delete the files in the database that are inconsistent with the files in the storage device, and batch store the new files in the database. If not, create a database and batch insert the multiple files in the storage device into the database. It is not necessary to clear the database every time the storage device is plugged in or unplugged, and the batch storage method is adopted when storing files, which reduces the scanning time and improves the scanning speed and efficiency.

[0190] Preferably, in combination withFigure 10 As shown in the content, the first scanning unit 1003 includes: a scanning module, a caching module, a judging module, and a storage module. The execution principles of each module are as follows:

[0191] The scanning module is used to scan the storage device to obtain new files that do not exist in the database.

[0192] The caching module is used to store the new files in the cache.

[0193] The judging module is used to judge whether the scanning of the storage device is completed. If the scanning of the storage device is completed, the storage module is executed. If the scanning of the storage device is not completed, the scanning module is returned to for execution.

[0194] The storage module is used to batch insert one or more new files in the cache into the database by using transaction processing.

[0195] In the embodiment of the present invention, the storage device is scanned to obtain new files that do not exist in the database, and the new files are stored in the cache. After the scanning of the storage device is completed, all the new files in the cache are inserted into the database by using transaction processing, reducing the scanning time and improving the scanning efficiency.

[0196] Preferably, in combination with Figure 10 As shown in the content, the first scanning unit 1003 includes: a scanning module, a caching module, a judging module, a storage module, and a determining module. The execution principles of each module are as follows:

[0197] The scanning module is used to scan the storage device to obtain new files that do not exist in the database.

[0198] The caching module is used to store the new files in the cache.

[0199] The judging module is used to judge whether the scanning of the storage device is completed. If the scanning of the storage device is completed, the storage module is executed. If the scanning of the storage device is not completed, the determining module is executed.

[0200] The storage module is used to batch insert one or more new files in the cache into the database by using transaction processing.

[0201] The determining module is used to determine whether the number of new files in the cache is equal to the number threshold. If the number of new files in the cache is less than the number threshold, the scanning module is returned to for execution. If the number of new files in the cache is equal to the number threshold, the storage module is executed to batch insert all the new files in the cache into the database, and the scanning module is returned to for execution.

[0202] In an embodiment of the present invention, a storage device is scanned to obtain new files that do not exist in the database, and the new files are stored in a cache. After the scanning of the storage device is completed, the new files in the cache are inserted into the database by using transaction processing. When the scanning of the storage device is not completed but the number of new files in the cache is equal to the number threshold, the new files in the cache are inserted into the database by using transaction processing. The scanning time is reduced and the scanning efficiency is improved.

[0203] Preferably, in combination with Figure 10 the content of, the second scanning unit 1005 includes: a scanning module, a determining module, a caching module, a judging module, and a storing module. The execution principles of each module are as follows:

[0204] The scanning module is configured to scan a storage device to obtain files of the storage device.

[0205] The determining module is configured to determine whether the files of the storage device exist in the database. If the files of the storage device exist in the database, the scanning module is returned for execution. If the files of the storage device do not exist in the database, the caching module is executed.

[0206] The caching module is configured to store the files of the storage device in the cache.

[0207] The judging module is configured to judge whether the scanning of the storage device is completed. If the scanning of the storage device is completed, the storing module is executed. If the scanning of the storage device is not completed, the scanning module is returned for execution.

[0208] The storing module is configured to batch insert one or more files in the cache into the database by using transaction processing.

[0209] In an embodiment of the present invention, after creating a database corresponding to a storage device, the files in the storage device are scanned. If the scanned files do not exist in the database, the files are stored in the cache. After the scanning of the storage device is completed, the files in the cache are batch inserted into the database by using transaction processing. The scanning time is reduced and the scanning efficiency is improved.

[0210] Preferably, in combination with Figure 10 the content of, the second scanning unit 1005 includes: a scanning module, a determining module, a caching module, a judging module, a storing module, and a number determining module. The execution principles of each module are as follows:

[0211] The scanning module is configured to scan a storage device to obtain files of the storage device.

[0212] The determining module is configured to determine whether the files of the storage device exist in the database. If the files of the storage device exist in the database, the scanning module is returned for execution. If the files of the storage device do not exist in the database, the caching module is executed.

[0213] A cache module for storing files of a storage device into a cache.

[0214] A judgment module for judging whether the scanning of the storage device is completed. If the scanning of the storage device is completed, execute the storage module. If the scanning of the storage device is not completed, execute the number determination module.

[0215] A storage module for batch inserting one or more files in the cache into a database by using transaction processing.

[0216] A number determination module for determining whether the number of files in the cache is equal to a number threshold. If the number of files in the cache is less than the number threshold, return to execute the scanning module. If the number of files in the cache is equal to the number threshold, execute the storage module to batch insert all files in the cache into the database, and return to execute the scanning module.

[0217] In an embodiment of the present invention, after creating a database corresponding to a storage device, scan the files in the storage device. If the scanned files do not exist in the database, store the files in the cache. When the scanning of the storage device is completed, batch insert the files in the cache into the database by using transaction processing. When the scanning of the storage device is not completed, but the number of files in the cache is equal to the number threshold, batch insert the files in the cache into the database by using transaction processing. The scanning time is reduced and the scanning efficiency is improved.

[0218] Preferably, in combination with Figure 10 the content shown, the system further includes:

[0219] A mounting unit for adding the ID of the storage device and mounting the storage device by using NetlinkEvent.

[0220] In summary, an embodiment of the present invention provides a method and a system for scanning files. The method is as follows: according to the ID of the storage device, determine whether there is a database corresponding to the ID; if so, delete the files in the database that are inconsistent with the files in the storage device; scan the storage device, obtain multiple new files that do not exist in the database, and batch insert the multiple new files into the database; if there is no database, create a database; scan the storage device, and batch insert multiple files in the scanned storage device into the database. In this solution, it is determined whether there is a database corresponding to the storage device. If so, delete the files in the database that are inconsistent with the files in the storage device, and batch store the new files in the database. If not, create a database and batch insert multiple files in the storage device into the database. It is not necessary to clear the database every time the storage device is unplugged and replugged, and a batch storage method is adopted when storing files, which reduces the scanning time and improves the scanning speed and efficiency.

[0221] Each embodiment in this specification is described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other, and the differences between each embodiment and other embodiments are emphasized. In particular, for a system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the description of the method embodiment. The systems and system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment. A person of ordinary skill in the art can understand and implement it without creative work.

[0222] Those skilled in the art can further realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in this article can be implemented by electronic hardware, computer software, or a combination of the two. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described according to functions in the above description. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.

[0223] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present invention. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for scanning files, characterized in that, the method includes: Determine whether there is a database corresponding to the ID according to the ID of the storage device; If the database exists, delete the files in the database that are inconsistent with the files in the storage device; Scan the storage device, obtain multiple new files that do not exist in the database, and batch insert the multiple new files into the database; If the database does not exist, create the database; Scan the storage device, and batch insert the multiple files in the storage device obtained by scanning into the database; Wherein, the scanning the storage device, obtaining multiple new files that do not exist in the database, and batch inserting the multiple new files into the database includes: Scan the storage device to obtain new files that do not exist in the database; Store the new files in the cache; Determine whether the scanning of the storage device is completed; If the scanning of the storage device is completed, use transaction processing to batch insert one or more of the new files in the cache into the database; If the scanning of the storage device is not completed, determine whether the number of the new files in the cache is equal to the number threshold; If the number of the new files in the cache is less than the number threshold, return to execute the step of scanning the storage device; If the number of the new files in the cache is equal to the number threshold, use transaction processing to batch insert all the new files in the cache into the database, and return to execute the step of scanning the storage device; Or, The scanning the storage device, obtaining multiple new files that do not exist in the database, and batch inserting the multiple new files into the database includes: Scan the storage device in the C++ layer according to JNI, obtain multiple new files that do not exist in the database, and batch insert the multiple new files into the database through JNI in the JAVA layer; Correspondingly, the scanning the storage device, and batch inserting the multiple files in the storage device obtained by scanning into the database includes: Scan the storage device in the C++ layer according to JNI, and batch insert the multiple files in the storage device obtained by scanning into the database through JNI in the JAVA layer.

2. The method according to claim 1, characterized in that, the deleting the files in the database that are inconsistent with the files in the storage device includes: Scan the files in the database; For each file obtained by scanning in the database, determine whether the file exists in the storage device; If the file does not exist in the storage device, delete the file.

3. The method according to claim 1, characterized in that, the scanning the storage device, obtaining multiple new files that do not exist in the database, and batch inserting the multiple new files into the database includes: Scan the storage device to obtain new files that do not exist in the database; Store the new files in the cache; Determine whether the scanning of the storage device is completed; If the scanning of the storage device is completed, use transaction processing to batch insert one or more of the new files in the cache into the database; If the scanning of the storage device is not completed, return to execute the step of scanning the storage device.

4. The method according to claim 1, wherein, the scanning of the storage device and batch inserting a plurality of files in the storage device obtained by the scanning into the database includes: scanning the storage device to obtain the files of the storage device; determining whether the files of the storage device exist in the database; if the files of the storage device exist in the database, return to execute the step of scanning the storage device; if the files of the storage device do not exist in the database, store the files of the storage device in the cache; judging whether the scanning of the storage device is completed; if the scanning of the storage device is completed, use transaction processing to batch insert one or more of the files in the cache into the database; if the scanning of the storage device is not completed, return to execute the step of scanning the storage device.

5. The method according to claim 1, wherein, the scanning of the storage device and batch inserting a plurality of files in the storage device obtained by the scanning into the database includes: scanning the storage device to obtain the files of the storage device; determining whether the files of the storage device exist in the database; if the files of the storage device exist in the database, return to execute the step of scanning the storage device; if the files of the storage device do not exist in the database, store the files of the storage device in the cache; judging whether the scanning of the storage device is completed; if the scanning of the storage device is completed, use transaction processing to batch insert one or more files in the cache into the database; if the scanning of the storage device is not completed, determine whether the number of files in the cache is equal to the number threshold; if the number of files in the cache is less than the number threshold, return to execute the step of scanning the storage device; if the number of files in the cache is equal to the number threshold, use transaction processing to batch insert all the files in the cache into the database and return to execute the step of scanning the storage device.

6. The method according to claim 1, wherein, before determining whether there is a database corresponding to the ID according to the ID of the storage device, further includes: using NetlinkEvent to add the ID of the storage device; mounting the storage device.

7. A system for scanning files, wherein, the system includes: a determination unit, configured to determine whether there is a database corresponding to the ID according to the ID of the storage device. If the database exists, execute the deletion unit. If the database does not exist, execute the creation unit; the deletion unit, configured to delete the files in the database that are inconsistent with the files in the storage device and execute the first scanning unit; The first scanning unit is configured to scan the storage device, obtain a plurality of new files that do not exist in the database, and batch insert the plurality of new files into the database; The creating unit is configured to create the database and execute the second scanning unit; The second scanning unit is configured to scan the storage device and batch insert the plurality of files in the storage device obtained by scanning into the database; Wherein, the first scanning unit is specifically configured to: scan the storage device according to JNI at the C++ layer, obtain a plurality of new files that do not exist in the database, and batch insert the plurality of new files into the database through JNI at the JAVA layer; Correspondingly, the second scanning unit is specifically configured to: scan the storage device according to JNI at the C++ layer, and batch insert the plurality of files in the storage device obtained by scanning into the database through JNI at the JAVA layer; Alternatively, the first scanning unit includes: A scanning module, configured to scan the storage device and obtain new files that do not exist in the database; A caching module, configured to store the new files in a cache; A judging module, configured to judge whether the scanning of the storage device is completed; if the scanning of the storage device is completed, execute the storage module; if the scanning of the storage device is not completed, execute the determining module; The storage module is configured to batch insert one or more of the new files in the cache into the database by using transaction processing; The determining module is configured to determine whether the number of the new files in the cache is equal to a number threshold; if the number of the new files in the cache is less than the number threshold, return to execute the scanning module; if the number of the new files in the cache is equal to the number threshold, execute the storage module to batch insert all the new files in the cache into the database, and return to execute the scanning module.

8. The system according to claim 7, wherein, The deleting unit is specifically configured to: scan the files in the database, and for each file obtained by scanning in the database, judge whether the file exists in the storage device, and if the file does not exist in the storage device, delete the file.

Citation Information

Patent Citations

  • Application reinforcement method and apparatus

    CN105740703A

  • Method, device and intelligent terminal for document scanning

    CN107247722A