CN116431241A - Resource conflict detection method, device, server and storage medium - Google Patents

Resource conflict detection method, device, server and storage medium Download PDF

Info

Publication number
CN116431241A
CN116431241A CN202310402160.8A CN202310402160A CN116431241A CN 116431241 A CN116431241 A CN 116431241A CN 202310402160 A CN202310402160 A CN 202310402160A CN 116431241 A CN116431241 A CN 116431241A
Authority
CN
China
Prior art keywords
resource
target
current
file
value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310402160.8A
Other languages
Chinese (zh)
Inventor
潘涛
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Shizhuang Information Technology Co ltd
Original Assignee
Shanghai Shizhuang Information Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Shizhuang Information Technology Co ltd filed Critical Shanghai Shizhuang Information Technology Co ltd
Priority to CN202310402160.8A priority Critical patent/CN116431241A/en
Publication of CN116431241A publication Critical patent/CN116431241A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating
    • G06F9/44552Conflict resolution, i.e. enabling coexistence of conflicting executables
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method, a device, a server and a storage medium for detecting resource conflict, wherein the method comprises the following steps: acquiring a resource file corresponding to an application program, and filtering the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program; storing an intermediate resource file based on a hash table, wherein keys of the hash table are file names and storage addresses of the intermediate resource file, and values of the hash table are file contents of the intermediate resource file; traversing the hash table, and determining a current MD5 value of a current intermediate resource file corresponding to a current key and a target MD5 value of a target intermediate resource file corresponding to a target key when the target key consistent with the current key exists in the hash table; when the current MD5 value is consistent with the target MD5 value, determining that the current intermediate resource file and the target intermediate resource file have resource conflict. According to the technical scheme, the resource conflict detection of the application program corresponding to the resource file is realized, and the speed and the efficiency of the resource conflict detection are improved.

Description

Resource conflict detection method, device, server and storage medium
Technical Field
The embodiment of the invention relates to the technical field of computers, in particular to a method, a device, a server and a storage medium for detecting resource conflict.
Background
At present, the C language is widely applied to development of application programs as an object-oriented programming language capable of writing cross-platform application software. When developing an application program in the C language, a plurality of components need to be developed, and the development of each component involves a large number of resource files (.rc files). After the application program development is finished, the resource files related to the application program development are required to be packaged, and a file package which can be downloaded and installed by a user is generated. When the resource files are packaged, resource conflict detection needs to be carried out on the resource files, and repeated resource files are deleted.
In the prior art, all resource files related to an application program are scanned, if a plurality of resource file renames exist in a scanning result, one rename resource file is reserved, and other rename resource files are deleted. And packaging the scanning result of deleting the rename resource file to obtain a file package corresponding to the application program.
However, if the file names of the resource files corresponding to the components in the application program are the same but the file contents are different, and if the scanning result includes multiple resource file renames, one rename resource file is reserved, and other rename resource files are deleted, the components in the application program can not find the corresponding resource files, which may cause the application program page blank screen or the application program flash back, and affect the user experience.
Disclosure of Invention
The invention provides a resource conflict detection method, a device, a server and a storage medium, which are used for realizing the resource conflict detection of a resource file corresponding to an application program.
In a first aspect, an embodiment of the present invention provides a method for detecting a resource conflict, including:
acquiring a resource file corresponding to an application program, and filtering the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program;
storing the intermediate resource file based on a hash table, wherein keys of the hash table are file names and storage addresses of the intermediate resource file, and values of the hash table are file contents of the intermediate resource file;
traversing the hash table, and determining a current MD5 value of a current intermediate resource file corresponding to a current key and a target MD5 value of a target intermediate resource file corresponding to a target key when the target key consistent with the current key exists in the hash table;
and when the current MD5 value is consistent with the target MD5 value, determining that the current intermediate resource file and the target intermediate resource file have resource conflict.
The technical scheme of the embodiment of the invention provides a resource conflict detection method, which comprises the following steps: acquiring a resource file corresponding to an application program, and filtering the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program; storing the intermediate resource file based on a hash table, wherein keys of the hash table are file names and storage addresses of the intermediate resource file, and values of the hash table are file contents of the intermediate resource file; traversing the hash table, and determining a current MD5 value of a current intermediate resource file corresponding to a current key and a target MD5 value of a target intermediate resource file corresponding to a target key when the target key consistent with the current key exists in the hash table; and when the current MD5 value is consistent with the target MD5 value, determining that the current intermediate resource file and the target intermediate resource file have resource conflict. According to the technical scheme, all resource files corresponding to the application program can be obtained, the resource files corresponding to the application program are filtered to obtain the intermediate resource files corresponding to the application program, the first filtering of the resource files is achieved, the resource files with no possibility of renaming are eliminated, the number of files needing to be subjected to continuous resource conflict detection is reduced, the file names, the storage addresses and the file contents corresponding to the intermediate resource files can be stored in the hash table, the global storage of the file names, the storage addresses and the file contents of the intermediate resource files corresponding to the application program is achieved, further the hash table can be traversed, when the target keys consistent with the current key exist in the hash table, the current MD5 value of the current intermediate resource file and the target MD5 value of the target intermediate resource file corresponding to the current key continue to carry out resource conflict detection on the current intermediate resource file and the target intermediate resource file corresponding to the target key, when the target keys consistent with the current key do not exist in the hash table, the current iteration is skipped and the hash table is returned to be determined again, the fact that the file with the target resource corresponding to the current MD5 value of the intermediate resource file is eliminated, and the target resource conflict can be further determined when the target resource corresponding to the target value of the current intermediate resource file is further confirmed. Therefore, when the file name and the file content of the resource file are consistent, the resource conflict exists in the resource file, and accurate resource conflict detection is realized. Of course, after determining that the current intermediate resource file and the target intermediate resource file have resource conflict, the current key can be determined again by traversing the hash table, so as to continue the resource conflict detection, and realize the resource conflict detection of the resource file corresponding to the application program. In addition, after twice filtering, the number of files required to be subjected to resource conflict detection by determining the MD5 value is greatly reduced, and the speed and the efficiency of resource conflict detection are improved.
Further, obtaining a resource file corresponding to the application program includes:
acquiring resource folders corresponding to all components in an application program;
and recursively traversing each resource folder to obtain resource files corresponding to each resource folder, and determining the resource files corresponding to all the resource folders as the resource files corresponding to the application program.
Further, the preset filtering rule is a filtering array length of resource files smaller than a preset value, and correspondingly, the filtering is performed on the resource files corresponding to the application program according to the preset filtering rule to obtain intermediate resource files corresponding to the application program, including:
determining the array length of each resource file corresponding to the application program;
and filtering the resource files with the array length smaller than a preset value in the resource files corresponding to the application program to obtain intermediate resource files corresponding to the application program.
Further, the storage address is a storage address of the intermediate resource file in a resource folder.
Further, determining the current MD5 value of the current intermediate resource file corresponding to the current key and the target MD5 value of the target intermediate resource file corresponding to the target key includes:
Determining file contents of a current intermediate resource file corresponding to the current key and file contents of a target intermediate resource file corresponding to the target key;
after the file content of the current intermediate resource file is converted into a current byte array, determining a current MD5 value corresponding to the current byte array as a current MD5 value of the current intermediate resource file;
after the file content of the target intermediate resource file is converted into a target byte array, determining a target MD5 value corresponding to the target byte array as a target MD5 value of the target intermediate resource file.
Further, determining the file content of the current intermediate resource file corresponding to the current key and the file content of the target intermediate resource file corresponding to the target key includes:
and reading the file content of the current intermediate resource file corresponding to the current key and the file content of the target intermediate resource file corresponding to the target key from the hash table based on UTF-8 coding.
Further, determining the current MD5 value corresponding to the current byte array as the current MD5 value of the current intermediate resource file includes:
after converting the current byte array into a current MD5 value byte array, converting the current MD5 value byte array into a current MD5 value, and determining the current MD5 value as the current MD5 value of the current intermediate resource file;
Determining the target MD5 value corresponding to the target byte array as the target MD5 value of the target intermediate resource file, including:
after the target byte array is converted into a target MD5 value byte array, the target MD5 value byte array is converted into a target MD5 value, and the target MD5 value is determined as the target MD5 value of the target intermediate resource file.
Further, after determining that the current intermediate resource file and the target intermediate resource file have resource conflicts, the method further includes:
and deleting the current intermediate resource file or the target intermediate resource file.
Further, the method further comprises the following steps:
and when the fact that the target key consistent with the current key does not exist in the hash table is determined, continuing to traverse the hash table.
Further, the method further comprises the following steps:
and when the current MD5 value is inconsistent with the target MD5 value, continuing to traverse the hash table.
In a second aspect, an embodiment of the present invention further provides a resource conflict detection apparatus, including:
the acquisition module is used for acquiring the resource file corresponding to the application program, and filtering the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program;
The storage module is used for storing the intermediate resource file based on a hash table, wherein keys of the hash table are file names and storage addresses of the intermediate resource file, and values of the hash table are file contents of the intermediate resource file;
the traversal module is used for traversing the hash table, and determining a current MD5 value of a current intermediate resource file corresponding to a current key and a target MD5 value of a target intermediate resource file corresponding to a target key when the target key consistent with the current key of the current intermediate resource file exists in the hash table;
and the determining module is used for determining that the current intermediate resource file and the target intermediate resource file have resource conflict when the current MD5 value is consistent with the target MD5 value.
In a third aspect, an embodiment of the present invention further provides a server, where the server includes:
at least one processor; and a memory communicatively coupled to the at least one processor;
wherein the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the resource conflict detection method as described in any one of the first aspects.
In a fourth aspect, embodiments of the present invention also provide a storage medium containing computer-executable instructions, which when executed by a computer processor, are for performing the resource conflict detection method according to any of the first aspects.
In a fifth aspect, the present application provides a computer program product comprising computer instructions which, when run on a computer, cause the computer to perform the resource conflict detection method as provided in the first aspect.
It should be noted that the above-mentioned computer instructions may be stored in whole or in part on a computer-readable storage medium. The computer readable storage medium may be packaged together with the processor of the resource conflict detection apparatus, or may be packaged separately from the processor of the resource conflict detection apparatus, which is not limited in this application.
The description of the second, third, fourth and fifth aspects of the present application may refer to the detailed description of the first aspect; also, the advantageous effects described in the second aspect, the third aspect, the fourth aspect, and the fifth aspect may refer to the advantageous effect analysis of the first aspect, and are not described herein.
In the present application, the names of the above-mentioned resource conflict detection apparatuses do not constitute limitations on the devices or function modules themselves, and in actual implementations, these devices or function modules may appear under other names. Insofar as the function of each device or function module is similar to the present application, it is within the scope of the claims of the present application and the equivalents thereof.
These and other aspects of the present application will be more readily apparent from the following description.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
Fig. 1 is a flowchart of a method for detecting resource conflict according to an embodiment of the present invention;
FIG. 2 is a flowchart of another method for detecting resource conflict according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of a device for detecting resource conflict according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a server according to an embodiment of the present invention.
Detailed Description
The invention is described in further detail below with reference to the drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting thereof. It should be further noted that, for convenience of description, only some, but not all of the structures related to the present invention are shown in the drawings.
The term "and/or" is herein merely an association relationship describing an associated object, meaning that there may be three relationships, e.g., a and/or B, may represent: a exists alone, A and B exist together, and B exists alone.
The terms "first" and "second" and the like in the description and in the drawings are used for distinguishing between different objects or for distinguishing between different processes of the same object and not for describing a particular sequential order of objects.
Furthermore, references to the terms "comprising" and "having" and any variations thereof in the description of the present application are intended to cover a non-exclusive inclusion. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those listed but may optionally include other steps or elements not listed or inherent to such process, method, article, or apparatus.
Before discussing exemplary embodiments in more detail, it should be mentioned that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although a flowchart depicts operations (or steps) as a sequential process, many of the operations can be performed in parallel, concurrently, or at the same time. Furthermore, the order of the operations may be rearranged. The process may be terminated when its operations are completed, but may have additional steps not included in the figures. The processes may correspond to methods, functions, procedures, subroutines, and the like. Furthermore, embodiments of the invention and features of the embodiments may be combined with each other without conflict.
It should be noted that, in the embodiments of the present application, words such as "exemplary" or "such as" are used to mean serving as an example, instance, or illustration. Any embodiment or design described herein as "exemplary" or "for example" should not be construed as preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "such as" is intended to present related concepts in a concrete fashion.
In the description of the present application, unless otherwise indicated, the meaning of "a plurality" means two or more.
When developing an application program in the C language, it is necessary to develop a plurality of components, and the development of each component involves a large number of resource files (.rc files). For ease of storage and use, the resource files involved in each component are typically grouped together in the form of resource folders. After the application program development is finished, the resource files related to the application program development are required to be packaged, and a file package which can be downloaded and installed by a user is generated. In order to reduce the volume of the file package, when the resource files related to application program development are packaged, conflict detection needs to be performed on the resource files so as to delete the resource files with the same file content.
In the prior art, determining resource folders corresponding to all components of an application program, determining resource files contained in each resource folder, scanning the resource files contained in the resource folders corresponding to all the components of the application program, and checking a scanning result. If the scanning result has the condition that a plurality of resource files are renamed, only one of the resource files with the renamed is reserved and the other resource files are deleted. And packaging the scanning result of deleting the resource file with the duplicate name to obtain a file package corresponding to the application program.
However, there may be resource files with the same file name but different file contents in the resource folders corresponding to the multiple components corresponding to the application program, if the resource files with the same name in the scanning result obtained by scanning the resource files contained in the resource folders corresponding to all the components of the application program are reserved only one resource file and other resource files are deleted, there may be components in the application program that cannot find the corresponding resource files, which may cause the application program to flash back or blank pages of the application program, and affect the user experience.
Therefore, the resource conflict detection method is provided, the resource files with the same file names and the same file contents in the application program are determined, namely the conflict detection of the resource files in the application program is realized, a data basis is provided for deleting the resource files with the same file names and the same file contents in the application program, and the application program page white screen or the application program flash back is avoided.
The resource conflict detection method proposed in the present application will be described in detail with reference to the drawings and embodiments.
Fig. 1 is a flowchart of a method for detecting resource conflict according to an embodiment of the present invention, where the method may be applied to a case where quick resource conflict detection needs to be performed on a resource file corresponding to an application, and the method may be performed by a resource conflict detection device, as shown in fig. 1, and specifically includes the following steps:
Step 110, obtaining a resource file corresponding to an application program, and filtering the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program.
The application program needs to call the resource file when running, and each component in the application program needs to call the resource file in the resource folder corresponding to each component when running. Thus, the resource files corresponding to the application may include resource files in the resource folder corresponding to each component within the application.
Specifically, an application program needing to perform resource conflict detection can be determined, resource folders corresponding to all components in the application program are obtained, and all resource files under the resource folders are determined in a recursion traversal mode to obtain the resource files corresponding to the application program.
The preset filtering rules can be used for eliminating resource files without possibility of renaming, namely eliminating resource files which do not need to carry out resource conflict detection in the resource files corresponding to the application program. After the resource file corresponding to the application program is obtained, the resource file corresponding to the application program can be filtered according to a preset filtering rule. And filtering the resource files corresponding to the application programs through preset filtering rules to obtain intermediate resource files corresponding to the application programs.
In the embodiment of the invention, all the resource files corresponding to the application program are obtained, after all the resource files corresponding to the application program are obtained, the resource files corresponding to the application program are filtered to obtain the intermediate resource files corresponding to the application program, the first filtering of the resource files is realized, the resource files without the possibility of renaming are eliminated, the number of the files for continuing to detect the resource conflict is reduced, and the resource conflict detection efficiency is improved.
Step 120, storing the intermediate resource file based on the hash table.
The key of the hash table is the file name and the storage address of the intermediate resource file, and the value of the hash table is the file content of the intermediate resource file.
Specifically, traversing the intermediate resource file corresponding to the application program, and determining the file name, the storage address and the file content corresponding to the intermediate resource file. The file name, the storage address and the file content corresponding to the intermediate resource file are stored in the hash table, specifically, the file name and the storage address of the intermediate resource file can be determined as keys of the hash table, and the file content of the intermediate resource file can be determined as keys of the hash table.
In the embodiment of the invention, the file name, the storage address and the file content corresponding to the intermediate resource file are stored in the hash table, so that the global storage of the file name, the storage address and the file content corresponding to the intermediate resource file is realized.
And 130, traversing the hash table, and determining a current MD5 value of a current intermediate resource file corresponding to a current key and a target MD5 value of a target intermediate resource file corresponding to a target key when the target key consistent with the current key exists in the hash table.
The keys of the hash table comprise file names and storage addresses of intermediate resource files, wherein the storage addresses are the storage addresses of the intermediate resource files in the resource folders, so that the storage addresses of different intermediate resource files in the same resource folder are unique, namely, the storage addresses of different intermediate resource files corresponding to the same component are unique, and therefore, different intermediate resource files in the resource folders corresponding to the same component must correspond to different keys. However, the storage addresses of the intermediate resource files in the different resource folders may be the same, that is, the storage addresses of the intermediate resource files corresponding to the different components may be the same, and thus, the resource files in the resource folders corresponding to the different components may correspond to the same key. Therefore, it is necessary to continue the resource conflict detection for the intermediate resource file corresponding to the application program.
Specifically, any key in the hash table is used as a current key, whether a target key consistent with the current key exists in the hash table is determined, and when the target key consistent with the current key exists in the hash table, it can be determined that resource conflict exists between the current intermediate resource file and the target intermediate resource file. Thus, it is desirable to determine whether there is a resource conflict between the current intermediate resource file and the target intermediate resource file. The MD5 value of the resource file may be used for resource conflict detection, and thus, the current MD5 value of the current intermediate resource file and the target MD5 value of the target intermediate resource file may be determined.
It should be noted that, when it is determined that there is no target key consistent with the current key in the hash table, it may be determined that there is no resource conflict between the current intermediate resource file and the target intermediate resource file, so that the current iteration may be skipped and the current key may be redetermined by traversing the hash table to continue to perform the resource conflict detection.
In the embodiment of the invention, when the target key consistent with the current key exists in the hash table, the resource conflict detection is continuously carried out on the current intermediate resource file corresponding to the current key and the target intermediate resource file corresponding to the target key based on the current MD5 value of the current intermediate resource file corresponding to the current key and the target MD5 value of the target intermediate resource file corresponding to the target key, when the target key consistent with the current key does not exist in the hash table, the current iteration is skipped, the hash table is traversed again, the current key is determined again, the second filtering of the resource file is realized, the resource file with inconsistent file names is eliminated, the number of files for continuously carrying out the resource conflict detection is further reduced, and the resource conflict detection efficiency is improved.
And 140, when the current MD5 value is consistent with the target MD5 value, determining that the current intermediate resource file and the target intermediate resource file have resource conflict.
Specifically, when it is determined that the current MD5 value is consistent with the target MD5 value, it may be determined that file contents of the current intermediate resource file are consistent with file contents of the target intermediate resource file, and further it may be determined that there is a resource conflict between the current intermediate resource file and the target intermediate resource file. Of course, after determining that there is a resource conflict between the current intermediate resource file and the target intermediate resource file, the current key may be re-determined by traversing the hash table to continue the resource conflict detection.
When the current MD5 value is inconsistent with the target MD5 value, it may be determined that the file content of the current intermediate resource file is inconsistent with the file content of the target intermediate resource file, and further it may be determined that there is no resource conflict between the current intermediate resource file and the target intermediate resource file, and at this time, the current key may be determined again by traversing the hash table, so as to continue to perform the resource conflict detection.
In the embodiment of the invention, when the current MD5 value corresponding to the current intermediate resource file is consistent with the target MD5 value corresponding to the target intermediate resource file, the file content of the current intermediate resource file is consistent with the file content of the target intermediate resource file, and further, the resource conflict between the current intermediate resource file and the target intermediate resource file can be determined. Of course, after determining that the current intermediate resource file and the target intermediate resource file have resource conflict, the current key can be determined again by traversing the hash table, so as to continue the resource conflict detection, and realize the resource conflict detection of the resource file corresponding to the application program.
The method for detecting the resource conflict provided by the embodiment of the invention comprises the following steps: acquiring a resource file corresponding to an application program, and filtering the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program; storing the intermediate resource file based on a hash table, wherein keys of the hash table are file names and storage addresses of the intermediate resource file, and values of the hash table are file contents of the intermediate resource file; traversing the hash table, and determining a current MD5 value of a current intermediate resource file corresponding to a current key and a target MD5 value of a target intermediate resource file corresponding to a target key when the target key consistent with the current key exists in the hash table; and when the current MD5 value is consistent with the target MD5 value, determining that the current intermediate resource file and the target intermediate resource file have resource conflict. According to the technical scheme, all resource files corresponding to the application program can be obtained, the resource files corresponding to the application program are filtered to obtain the intermediate resource files corresponding to the application program, the first filtering of the resource files is achieved, the resource files with no possibility of renaming are eliminated, the number of files needing to be subjected to continuous resource conflict detection is reduced, the file names, the storage addresses and the file contents corresponding to the intermediate resource files can be stored in the hash table, the global storage of the file names, the storage addresses and the file contents of the intermediate resource files corresponding to the application program is achieved, further the hash table can be traversed, when the target keys consistent with the current key exist in the hash table, the current MD5 value of the current intermediate resource file and the target MD5 value of the target intermediate resource file corresponding to the current key continue to carry out resource conflict detection on the current intermediate resource file and the target intermediate resource file corresponding to the target key, when the target keys consistent with the current key do not exist in the hash table, the current iteration is skipped and the hash table is returned to be determined again, the fact that the file with the target resource corresponding to the current MD5 value of the intermediate resource file is eliminated, and the target resource conflict can be further determined when the target resource corresponding to the target value of the current intermediate resource file is further confirmed. Therefore, when the file name and the file content of the resource file are consistent, the resource conflict exists in the resource file, and accurate resource conflict detection is realized. Of course, after determining that the current intermediate resource file and the target intermediate resource file have resource conflict, the current key can be determined again by traversing the hash table, so as to continue the resource conflict detection, and realize the resource conflict detection of the resource file corresponding to the application program. In addition, after twice filtering, the number of files required to be subjected to resource conflict detection by determining the MD5 value is greatly reduced, and the speed and the efficiency of resource conflict detection are improved.
Fig. 2 is a flowchart of another method for detecting resource conflict according to an embodiment of the present invention, where the method is implemented based on the foregoing embodiment. As shown in fig. 2, in this embodiment, the method may further include:
step 210, obtaining resource folders corresponding to all components in the application program.
In the embodiment of the invention, the resource conflict detection can be performed on the resource file of the application program based on the customized Gradle plug-in. Therefore, before resource conflict detection occurs, the Gradle plugin needs to be configured. Specifically, an application () function is customized at the integration time program entry corresponding to the Gradle plug-in, so that the Gradle plug-in can be configured, and the Gradle plug-in can be used for defining resource conflict detection. The apply () function can be imported into the integration time program portal through the implementation class of the custom plug in interface. And customizing the Gradle Task at a corresponding run-time program inlet of the Gradle plug-in, so that the Gradle plug-in can perform resource conflict detection by executing the Gradle Task. The Gradle plugin can call an apply () function to initialize the Gradle plugin, so that the Gradle plugin can be configured, and also can register Gradle Task to a Android Assemble Task reference chain of the project code, and add call timing constraint, so that the Gradle plugin can execute an asssemble debug or asssemble release Task based on the running project code during running, and the running program entry is called according to preset time to detect resource conflict.
In addition, the integrated program entry may be used to configure the execution logic of the runtime program entry, which may only execute after the pre-build phase of Android Gradle Plugin and before the processmanifield phase, otherwise, it may not be possible to accurately recursively traverse the resource file.
In order to flexibly control whether the plug in executes the resource conflict detection, a preset value can be set in the plug in, when the preset value is true, the resource conflict detection is executed, and when the preset value is false, the resource conflict detection is not executed. The preset value is used for providing an external switch, and the preset value can be determined according to actual requirements so as to flexibly control whether the Plugin plug-in unit executes resource conflict detection.
An afterevaluation callback of the project object can also be registered, whether the project object introduces a Gradle plugin or not is judged, and the project object not introduced with the Gradle plugin is filtered. The project object may be passed through the Gradle plug-in interface and may be stored in memory. The Gradle Plugin can call various interfaces based on the project object, for example, can call a project. Variant. AllRawAndresource api of the acquisition application, call a java. System. Properties api to acquire a preset value of the Plugin, call a MessageDiget. Digest (byte [ ]) api and a Hex. EncodeHex (byte [ ], char [ ]) api to determine the MD5 value of the resource file based on the project object.
All variants of Android Extension in the project code may also be collected to find the release Variant therein. The names of the processVariantManifest tasks are assembled through the actual names of the release variants, and custom actions are added at the beginning of the tasks, so that the actions serve as running program entries, constraint on the execution sequence of the running program is realized, and the resource conflict detection is ensured to be executed before the processManifest stage.
After the configuration of the Plugin is completed, the resource folders corresponding to all components in the application program needing to perform resource conflict detection can be obtained based on the Plugin, namely RawAndroidResources Files which belongs to the Release variable can be obtained based on the project object calling project.
In the embodiment of the invention, after the configuration of the plug-in is completed, the interface can be called to acquire RawAndroidResources Files of the application program.
Step 211, recursively traversing each resource folder to obtain resource files corresponding to each resource folder, and determining the resource files corresponding to all the resource folders as the resource files corresponding to the application program.
Specifically, the resource folder in RawAndroidResources Files is expanded, all the resource files under RawAndroidResources Files are determined by a recursive traversal mode, and the resource files corresponding to the application program are obtained. Thus, the resource files corresponding to the application program are acquired, the acquisition range of the resource files can be maximized, the resource files are ensured not to be omitted, and all the resource files corresponding to the application program can be acquired.
In addition, by inserting the custom Action in the processManifest, the resource file is ensured not to be modified by the compiling operation of the plug in plug-in, and the accuracy of the resource file is ensured.
In the embodiment of the invention, determining all resource files of the application program is realized by traversing RawAndroidResources Files of the application program.
And 212, filtering the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program.
In order to improve the expansibility of resource conflict detection, the resource files without possibility of renaming are filtered through preset filtering rules, namely the resource files which do not need to detect the conflict are filtered. In practical application, the preset filtering rules may be set according to practical requirements, which are not limited herein. For example, the preset filtering rule may be a filtering resource file in a resource folder corresponding to the preset component, or may be a filtering resource file whose array length satisfies a preset numerical condition. After the resource files corresponding to the application program are obtained, the resource files corresponding to the application program can be filtered according to a preset filtering rule to obtain intermediate resource files corresponding to the application program, for example, the resource files in the resource folder corresponding to the preset component are filtered, or the resource files with the array length meeting the preset numerical condition are filtered.
In one embodiment, the preset filtering rule is to filter resource files with an array length smaller than a preset value, and accordingly, step 212 may specifically include:
determining the array length of each resource file corresponding to the application program; and filtering the resource files with the array length smaller than a preset value in the resource files corresponding to the application program to obtain intermediate resource files corresponding to the application program.
Specifically, the preset filtering rule is to filter resource files with array lengths smaller than a preset value, namely, the resource files with array lengths smaller than the preset value in the resource files corresponding to the application program can be filtered, and the target resource files are obtained. The preset value may be set according to actual requirements, and is not particularly limited herein, for example, the preset value may be 1. Specifically, the array length of each resource file corresponding to the application program can be determined, the array length of the resource file is compared with a preset value, if the array length of the resource file is greater than the preset value, the resource file is reserved, and if the array length of the resource file is less than the preset value, the resource file is filtered. Therefore, after the resource files with the array lengths smaller than the preset value in the resource files corresponding to the application program are filtered, the intermediate resource files corresponding to the application program can be obtained, and the array lengths of the intermediate resource files are all larger than the preset value.
Compared with the resource files, the number of the intermediate resource files is greatly reduced, and only the intermediate resource files are required to be subjected to resource conflict detection continuously, so that the number of the files subjected to resource conflict detection continuously is reduced.
In the embodiment of the invention, the intermediate resource files corresponding to the application program are obtained by filtering the resource files corresponding to the application program based on the preset filtering rule, so that the first filtering of the resource files is realized, the resource files without possibility of renaming are eliminated, only the intermediate resource files are required to be continuously subjected to resource conflict detection, the number of the files continuously subjected to resource conflict detection is reduced, and the resource conflict detection efficiency is improved.
Step 213, storing the intermediate resource file based on the hash table.
The key of the hash table is a file name and a storage address of the intermediate resource file, the storage address is a storage address of the intermediate resource file in a resource folder, and the value of the hash table is the file content of the intermediate resource file.
Specifically, according to the resource folder corresponding to the component and the storage sequence of the resource files in the resource folder, traversing the intermediate resource file corresponding to the application program, and determining the file name, the storage address and the file content corresponding to the intermediate resource file. The file name and the storage address of the intermediate resource file are determined as keys of the hash table, and the file content of the intermediate resource file is determined as keys of the hash table.
The underlying data structure object includes FILE content (FILE field, data TYPE is a character string), MD5 value (MD 5 field, data TYPE is a FILE object) of the resource FILE, FILE NAME (file_name field, data TYPE is a character string) of the resource FILE, extension (file_type field, data TYPE is a character string) of the resource FILE, and ID object (ID field, data TYPE is a character string) of the resource FILE. The key of the hash table is the ID object of the resource file in the bottom data structure object, and the value type of the hash table is the file content of the resource file in the bottom data structure object.
In the embodiment of the invention, the file name, the storage address and the file content corresponding to the intermediate resource file are stored in the hash table, so that the global storage of the file name, the storage address and the file content corresponding to the intermediate resource file is realized.
Step 214, traversing the hash table, and determining any key stored in the hash table as the current key.
Specifically, the hash table is traversed to perform hash retrieval on the hash table, and any key stored in the hash table is determined as the current key.
Step 215, determining whether a target key consistent with the current key exists in the hash table.
Specifically, it may be determined whether a target key consistent with the current key exists in the hash table by comparing the current key with other keys stored in the hash table.
If the target key consistent with the current key exists in the hash table, executing step 216; otherwise, go back to step 214.
When it is determined that the target key consistent with the current key does not exist in the hash table, it may be determined that there is no resource conflict between the current intermediate resource file and the target intermediate resource file, so that the current iteration may be skipped and the current key may be re-determined by traversing the hash table to continue the resource conflict detection.
When it is determined that the target key consistent with the current key exists in the hash table, it may be determined that the file name and the storage address of the current intermediate resource file corresponding to the current key are consistent with the file name of the target intermediate resource file corresponding to the target key. At this time, it can be known that the file content of the current intermediate resource file may be consistent with the file content of the target intermediate resource file, that is, there may be resource conflict between the current intermediate resource file and the target intermediate resource file. Therefore, it is necessary to continue to perform resource conflict detection on the current intermediate resource file and the target intermediate resource file.
Step 216, determining a current MD5 value of the current intermediate resource file corresponding to the current key and a target MD5 value of the target intermediate resource file corresponding to the target key.
In one embodiment, step 216 may specifically include:
determining file contents of a current intermediate resource file corresponding to the current key and file contents of a target intermediate resource file corresponding to the target key; after the file content of the current intermediate resource file is converted into a current byte array, determining a current MD5 value corresponding to the current byte array as a current MD5 value of the current intermediate resource file; after the file content of the target intermediate resource file is converted into a target byte array, determining a target MD5 value corresponding to the target byte array as a target MD5 value of the target intermediate resource file.
Specifically, when the MD5 values of the resource files are consistent, it may be determined that the file contents of the resource files are consistent, that is, it may be determined that the resource files have resource conflicts. Thus, the MD5 value of the resource file may be used for resource conflict detection. Specifically, the MD5 value of the resource file may be determined from the file content of the resource file.
Further, determining the file content of the current intermediate resource file corresponding to the current key and the file content of the target intermediate resource file corresponding to the target key includes:
And reading the file content of the current intermediate resource file corresponding to the current key and the file content of the target intermediate resource file corresponding to the target key from the hash table based on UTF-8 coding.
Specifically, the current file content in the form of the character string of the current intermediate resource file corresponding to the current key is read in the hash table based on UTF-8 encoding, and the target file content in the form of the character string of the target intermediate resource file corresponding to the target key is read in the hash table based on UTF-8 encoding.
The current file content in the form of character strings can be further converted into a current byte array, and the target file content in the form of character strings can be converted into a target byte array.
Further, determining the current MD5 value corresponding to the current byte array as the current MD5 value of the current intermediate resource file includes: after converting the current byte array into a current MD5 value byte array, converting the current MD5 value byte array into a current MD5 value, and determining the current MD5 value as the current MD5 value of the current intermediate resource file; determining the target MD5 value corresponding to the target byte array as the target MD5 value of the target intermediate resource file, including: after the target byte array is converted into a target MD5 value byte array, the target MD5 value byte array is converted into a target MD5 value, and the target MD5 value is determined as the target MD5 value of the target intermediate resource file.
Specifically, the current byte array can be converted into the current MD5 value byte array by calling a message digest (byte [ ]) api provided by JDK based on a project object, the current MD5 value byte array can be converted into 32character hex string in 16-ary representation by calling a hex (byte [ ], char [ ]) api provided by JDK based on the project object, the current MD5 value of the current intermediate resource file is obtained, and the current MD5 value is denoted as MD 5-payoad-1, so as to determine the current MD5 value corresponding to the current intermediate resource file. The method can also call a MessageDiget (byte [ ]) api provided by the JDK based on the project object to convert the target byte array into a target MD5 value byte array, call a Hex.encoyHex (byte [ ], char [ ]) api provided by the JDK based on the project object to convert the target MD5 value byte array into 32character hex string in 16-system representation to obtain a target MD5 value of the target intermediate resource file, and record the target MD5 value as MD5-PAYLOAD-2 to realize the determination of the target MD5 value corresponding to the target intermediate resource file.
In the embodiment of the invention, the current key is determined by traversing the hash table, when the target key consistent with the current key exists in the hash table, the current MD5 value of the current intermediate resource file corresponding to the current key and the target MD5 value of the target intermediate resource file corresponding to the target key are determined, the resource conflict detection is continuously carried out on the current intermediate resource file and the target intermediate resource file based on the current MD5 value and the target MD5 value, when the target key consistent with the current key does not exist in the hash table, the current iteration is skipped, the current key is determined again by returning to the traverse hash table, the second filtering of the resource file is realized, the resource file with inconsistent file names is eliminated, the number of files for continuously carrying out the resource conflict detection is further reduced, and the resource conflict detection efficiency is improved.
Step 217, determining whether the current MD5 value is consistent with the target MD5 value.
Specifically, the value of MD5-PAYLOAD-1 and the value of MD5-PAYLOAD-2 are compared, if the value of MD5-PAYLOAD-1 and the value of MD5-PAYLOAD-2 are consistent, step 218 is performed, otherwise, step 214 is performed back.
When the MD5 values of the resource files are consistent, the file content of the resource files can be determined to be consistent. The current MD5 value and the target MD5 value may be used to determine whether the file content of the current intermediate resource file is consistent with the file content of the target intermediate resource file. When it is determined that the value of MD5-PAYLOAD-1 and the value of MD5-PAYLOAD-2 are consistent, it may be determined that the file contents of the current intermediate resource file and the file contents of the target intermediate resource file are consistent. When the value of MD5-PAYLOAD-1 and the value of MD5-PAYLOAD-2 are inconsistent, the file content of the current intermediate resource file and the file content of the target intermediate resource file can be determined to be inconsistent, further, the fact that the current intermediate resource file and the target intermediate resource file have no resource conflict can be determined, and at the moment, the current key can be determined again by traversing the hash table so as to continue to detect the resource conflict.
Step 218, determining that there is a resource conflict between the current intermediate resource file and the target intermediate resource file.
After determining that the file content of the current intermediate resource file is consistent with the file content of the target intermediate resource file, it can be determined that the current intermediate resource file and the target intermediate resource file have resource conflict. Of course, after determining that there is a resource conflict between the current intermediate resource file and the target intermediate resource file, the current key may be determined again by traversing the hash table, so as to continue the resource conflict detection.
The global storage realized by storing the file name, the storage address and the file content of the target resource file into the hash table and the hash retrieval realized by traversing the keys in the hash table are all completed in one iteration of the traversal scanning, so that the time complexity of the resource conflict detection performed on the resource file of the application program is O (n), namely, the time required for the resource conflict detection on the resource file of the application program is positively correlated with the number of the resource files required for the resource conflict detection. Because the resource files corresponding to the application program are filtered twice, only the MD5 value of the resource files with a small part of possible resource conflicts is calculated, the MD5 value of all the resource files corresponding to the application program is not required to be calculated, the number of the resource files with the MD5 value required to be calculated is reduced, the time required for detecting the resource conflicts of the resource files of the application program is further reduced, and the resource conflict detection efficiency is improved.
Step 219, deleting the current intermediate resource file or the target intermediate resource file.
Specifically, after determining that the file content of the current intermediate resource file is consistent with the file content of the target intermediate resource file, it may be determined that there is a resource conflict between the current intermediate resource file and the target intermediate resource file, and then the current intermediate resource file or the target intermediate resource file may be deleted. The method and the device realize deleting one of the resource files with the same file name and file content in the resource files corresponding to the application program, avoid mistakenly deleting the resource files with the same file name but different file content, reduce the occurrence probability of application program page blank screen or application program flash back, and promote user experience.
The method for detecting the resource conflict provided by the embodiment of the invention comprises the following steps: acquiring resource folders corresponding to all components in an application program; recursively traversing each resource folder to obtain resource files corresponding to each resource folder, and determining the resource files corresponding to all the resource folders as the resource files corresponding to the application program; filtering the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program; storing the intermediate resource file based on a hash table; traversing the hash table; determining whether a target key consistent with the current key exists in the hash table; when the fact that the target key consistent with the current key does not exist in the hash table is determined, returning to traverse the hash table; when a target key consistent with the current key exists in the hash table, determining a current MD5 value of a current intermediate resource file corresponding to the current key and a target MD5 value of a target intermediate resource file corresponding to the target key; determining whether the current MD5 value is consistent with the target MD5 value; returning to traverse the hash table when the current MD5 value is inconsistent with the target MD5 value; and when the current MD5 value is consistent with the target MD5 value, determining that the current intermediate resource file and the target intermediate resource file have resource conflict. According to the technical scheme, the Plugin plug-in can be configured firstly, so that the Plugin plug-in has the function of resource conflict detection, all resource files of an application program can be obtained based on the Plugin plug-in, the intermediate resource files corresponding to the application program are obtained by filtering the resource files without the possibility of renaming through a preset filtering rule, the first filtering of the resource files is realized, the resource files without the possibility of renaming are eliminated, the number of files needing to continue resource conflict detection is reduced, the file names, the storage addresses and the file contents corresponding to the intermediate resource files are stored in a hash table, the file names, the storage addresses and the file contents of the intermediate resource files corresponding to the application program are stored in a global storage hash table, any key stored in the hash table is determined to be the current key, when the target key consistent with the current key exists in the hash table is determined, the conflict of the current intermediate resource files corresponding to the current key is continuously eliminated based on the current MD5 value of the current intermediate resource file corresponding to the target MD5 value of the target intermediate resource file corresponding to the current key, the conflict of the target resource files is further determined when the target key is not consistent with the current key exists in the MD, the target key is further determined, the conflict of the target resource is further is reduced, and the conflict of the target resource is further determined in the state is further determined when the target value is not consistent with the target key corresponding to the current target key, and the target value is further determined, and then, the existence of resource conflict between the current intermediate resource file and the target intermediate resource file can be determined, when the current MD5 value corresponding to the current intermediate resource file is inconsistent with the target MD5 value corresponding to the target intermediate resource file, the file content of the current intermediate resource file is inconsistent with the file content of the target intermediate resource file, and then, the existence of resource conflict between the current intermediate resource file and the target intermediate resource file can be determined, so that the resource conflict detection of the current intermediate resource file and the target intermediate resource file is realized. Of course, after determining that the current intermediate resource file and the target intermediate resource file have or have no resource conflict, the current key can be determined again by traversing the hash table, so as to continue to perform resource conflict detection, and realize resource conflict detection of the resource file corresponding to the application program. The time required by the resource conflict detection of the resource files of the application program is positively correlated with the number of the resource files required by the resource conflict detection, after the two times of filtering, the number of the files required by the resource conflict detection by determining the MD5 value is greatly reduced, the time required by the resource conflict detection of the resource files of the application program is reduced, and the resource conflict detection efficiency is improved. In addition, deleting one of the resource files with the same file name and file content in the resource files corresponding to the application program can avoid mistakenly deleting the resource files with the same file name but different file content, reduce the occurrence probability of application program page white screen or application program flash back, and promote user experience.
Fig. 3 is a schematic structural diagram of a device for detecting resource conflict according to an embodiment of the present invention, where the device may be suitable for a situation where quick resource conflict detection needs to be performed on a resource file corresponding to an application, so as to improve the efficiency of resource conflict detection. The apparatus may be implemented in software and/or hardware and is typically integrated in a server.
As shown in fig. 3, the apparatus includes:
the obtaining module 310 is configured to obtain a resource file corresponding to an application program, and filter the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program;
a storage module 320, configured to store the intermediate resource file based on a hash table, where a key of the hash table is a file name and a storage address of the intermediate resource file, and a value of the hash table is a file content of the intermediate resource file;
a traversing module 330, configured to traverse the hash table, and determine, when a target key consistent with a current key of a current intermediate resource file exists in the hash table, a current MD5 value of the current intermediate resource file corresponding to the current key and a target MD5 value of a target intermediate resource file corresponding to the target key;
And the determining module 340 is configured to determine that a resource conflict exists between the current intermediate resource file and the target intermediate resource file when the current MD5 value is determined to be consistent with the target MD5 value.
The resource conflict detection device provided by the embodiment obtains a resource file corresponding to an application program, and filters the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program; storing the intermediate resource file based on a hash table, wherein keys of the hash table are file names and storage addresses of the intermediate resource file, and values of the hash table are file contents of the intermediate resource file; traversing the hash table, and determining a current MD5 value of a current intermediate resource file corresponding to a current key and a target MD5 value of a target intermediate resource file corresponding to a target key when the target key consistent with the current key exists in the hash table; and when the current MD5 value is consistent with the target MD5 value, determining that the current intermediate resource file and the target intermediate resource file have resource conflict. According to the technical scheme, all resource files corresponding to the application program can be obtained, the resource files corresponding to the application program are filtered to obtain the intermediate resource files corresponding to the application program, the first filtering of the resource files is achieved, the resource files with no possibility of renaming are eliminated, the number of files needing to be subjected to continuous resource conflict detection is reduced, the file names, the storage addresses and the file contents corresponding to the intermediate resource files can be stored in the hash table, the global storage of the file names, the storage addresses and the file contents of the intermediate resource files corresponding to the application program is achieved, further the hash table can be traversed, when the target keys consistent with the current key exist in the hash table, the current MD5 value of the current intermediate resource file and the target MD5 value of the target intermediate resource file corresponding to the current key continue to carry out resource conflict detection on the current intermediate resource file and the target intermediate resource file corresponding to the target key, when the target keys consistent with the current key do not exist in the hash table, the current iteration is skipped and the hash table is returned to be determined again, the fact that the file with the target resource corresponding to the current MD5 value of the intermediate resource file is eliminated, and the target resource conflict can be further determined when the target resource corresponding to the target value of the current intermediate resource file is further confirmed. Therefore, when the file name and the file content of the resource file are consistent, the resource conflict exists in the resource file, and accurate resource conflict detection is realized. Of course, after determining that the current intermediate resource file and the target intermediate resource file have resource conflict, the current key can be determined again by traversing the hash table, so as to continue the resource conflict detection, and realize the resource conflict detection of the resource file corresponding to the application program. In addition, after twice filtering, the number of files required to be subjected to resource conflict detection by determining the MD5 value is greatly reduced, and the speed and the efficiency of resource conflict detection are improved.
On the basis of the foregoing embodiment, the preset filtering rule is to filter resource files with an array length smaller than a preset value, and accordingly, the obtaining module 310 is specifically configured to:
acquiring resource folders corresponding to all components in an application program; recursively traversing each resource folder to obtain resource files corresponding to each resource folder, and determining the resource files corresponding to all the resource folders as the resource files corresponding to the application program; determining the array length of each resource file corresponding to the application program; and filtering the resource files with the array length smaller than a preset value in the resource files corresponding to the application program to obtain intermediate resource files corresponding to the application program.
In one embodiment, the storage address is a storage address of the intermediate resource file in a resource folder.
Based on the above embodiment, the traversing module 330 is specifically configured to:
traversing the hash table, and determining the file content of the current intermediate resource file corresponding to the current key and the file content of the target intermediate resource file corresponding to the target key when the target key consistent with the current key of the current intermediate resource file exists in the hash table; after the file content of the current intermediate resource file is converted into a current byte array, determining a current MD5 value corresponding to the current byte array as a current MD5 value of the current intermediate resource file; after the file content of the target intermediate resource file is converted into a target byte array, determining a target MD5 value corresponding to the target byte array as a target MD5 value of the target intermediate resource file.
In one embodiment, determining the file content of the current intermediate resource file corresponding to the current key and the file content of the target intermediate resource file corresponding to the target key includes:
and reading the file content of the current intermediate resource file corresponding to the current key and the file content of the target intermediate resource file corresponding to the target key from the hash table based on UTF-8 coding.
In one embodiment, determining the current MD5 value corresponding to the current byte array as the current MD5 value of the current intermediate resource file includes:
after converting the current byte array into a current MD5 value byte array, converting the current MD5 value byte array into a current MD5 value, and determining the current MD5 value as the current MD5 value of the current intermediate resource file;
determining the target MD5 value corresponding to the target byte array as the target MD5 value of the target intermediate resource file, including:
after the target byte array is converted into a target MD5 value byte array, the target MD5 value byte array is converted into a target MD5 value, and the target MD5 value is determined as the target MD5 value of the target intermediate resource file.
On the basis of the above embodiment, the device further includes:
And the deleting module is used for deleting the current intermediate resource file or the target intermediate resource file.
On the basis of the above embodiment, the device further includes:
and the first execution module is used for continuing to traverse the hash table when the target key consistent with the current key does not exist in the hash table.
On the basis of the above embodiment, the device further includes:
and the second execution module is used for continuing to traverse the hash table when the current MD5 value is determined to be inconsistent with the target MD5 value.
The resource conflict detection device provided by the embodiment of the invention can execute the resource conflict detection method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of executing the resource conflict detection method.
It should be noted that, in the embodiment of the resource conflict detection apparatus, each unit and module included are only divided according to the functional logic, but not limited to the above-mentioned division, so long as the corresponding functions can be implemented; in addition, the specific names of the functional units are also only for distinguishing from each other, and are not used to limit the protection scope of the present invention.
Fig. 4 is a schematic structural diagram of a server according to an embodiment of the present invention. Fig. 4 shows a block diagram of an exemplary server 4 suitable for use in implementing embodiments of the invention. The server 4 shown in fig. 4 is only an example and should not be construed as limiting the functionality and scope of use of the embodiments of the present invention.
As shown in fig. 4, the server 4 is in the form of a general purpose computing electronic device. The components of the server 4 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, a bus 18 that connects the various system components, including the system memory 28 and the processing units 16.
Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, and a local bus using any of a variety of bus architectures. By way of example, and not limitation, such architectures include Industry Standard Architecture (ISA) bus, micro channel architecture (MAC) bus, enhanced ISA bus, video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
The server 4 typically includes a variety of computer system readable media. Such media can be any available media that is accessible by server 4 and includes both volatile and nonvolatile media, removable and non-removable media.
The system memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 30 and/or cache memory 32. The server 4 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 34 may be used to read from or write to non-removable, nonvolatile magnetic media (not shown in FIG. 4, commonly referred to as a "hard disk drive"). Although not shown in fig. 4, a magnetic disk drive for reading from and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), and an optical disk drive for reading from or writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In such cases, each drive may be coupled to bus 18 through one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to carry out the functions of the embodiments of the invention.
A program/utility 40 having a set (at least one) of program modules 42 may be stored in, for example, system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment. Program modules 42 generally perform the functions and/or methods of the embodiments described herein.
The server 4 may also communicate with one or more external devices 14 (e.g., keyboard, pointing device, display 24, etc.), one or more devices that enable a user to interact with the server 4, and/or any devices (e.g., network card, modem, etc.) that enable the server 4 to communicate with one or more other computing devices. Such communication may occur through an input/output (I/O) interface 22. Also, the server 4 may communicate with one or more networks such as a Local Area Network (LAN), a Wide Area Network (WAN) and/or a public network, such as the Internet, via the network adapter 20. As shown in fig. 4, the network adapter 20 communicates with other modules of the server 4 via the bus 18. It should be appreciated that although not shown in fig. 4, other hardware and/or software modules may be used in connection with server 4, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, data backup storage systems, and the like.
The processing unit 16 executes various functional applications and page displays by running programs stored in the system memory 28, for example, implementing the resource conflict detection method provided by the present embodiment, the method includes:
acquiring a resource file corresponding to an application program, and filtering the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program;
storing the intermediate resource file based on a hash table, wherein keys of the hash table are file names and storage addresses of the intermediate resource file, and values of the hash table are file contents of the intermediate resource file;
traversing the hash table, and determining a current MD5 value of a current intermediate resource file corresponding to a current key and a target MD5 value of a target intermediate resource file corresponding to a target key when the target key consistent with the current key exists in the hash table;
and when the current MD5 value is consistent with the target MD5 value, determining that the current intermediate resource file and the target intermediate resource file have resource conflict.
Of course, those skilled in the art will understand that the processor may also implement the technical solution of the resource conflict detection method provided in any embodiment of the present invention.
An embodiment of the present invention provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements a resource conflict detection method such as provided by the embodiment of the present invention, the method including:
acquiring a resource file corresponding to an application program, and filtering the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program;
storing the intermediate resource file based on a hash table, wherein keys of the hash table are file names and storage addresses of the intermediate resource file, and values of the hash table are file contents of the intermediate resource file;
traversing the hash table, and determining a current MD5 value of a current intermediate resource file corresponding to a current key and a target MD5 value of a target intermediate resource file corresponding to a target key when the target key consistent with the current key exists in the hash table;
and when the current MD5 value is consistent with the target MD5 value, determining that the current intermediate resource file and the target intermediate resource file have resource conflict.
The computer storage media of embodiments of the invention may take the form of any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. The computer readable storage medium may be, for example, but not limited to: an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the computer-readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computer (for example, through the Internet using an Internet service provider).
It will be appreciated by those of ordinary skill in the art that the modules or steps of the invention described above may be implemented in a general purpose computing device, they may be centralized on a single computing device, or distributed over a network of computing devices, or they may alternatively be implemented in program code executable by a computer device, such that they are stored in a memory device and executed by the computing device, or they may be separately fabricated as individual integrated circuit modules, or multiple modules or steps within them may be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
In addition, the technical scheme of the invention can acquire, store, use, process and the like the data, which accords with the relevant regulations of national laws and regulations.
Note that the above is only a preferred embodiment of the present invention and the technical principle applied. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, while the invention has been described in connection with the above embodiments, the invention is not limited to the embodiments, but may be embodied in many other equivalent forms without departing from the spirit or scope of the invention, which is set forth in the following claims.

Claims (13)

1. A method for detecting resource conflict, comprising:
acquiring a resource file corresponding to an application program, and filtering the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program;
storing the intermediate resource file based on a hash table, wherein keys of the hash table are file names and storage addresses of the intermediate resource file, and values of the hash table are file contents of the intermediate resource file;
traversing the hash table, and determining a current MD5 value of a current intermediate resource file corresponding to a current key and a target MD5 value of a target intermediate resource file corresponding to a target key when the target key consistent with the current key exists in the hash table;
and when the current MD5 value is consistent with the target MD5 value, determining that the current intermediate resource file and the target intermediate resource file have resource conflict.
2. The method for detecting resource conflict according to claim 1, wherein obtaining a resource file corresponding to an application program includes:
acquiring resource folders corresponding to all components in an application program;
and recursively traversing each resource folder to obtain resource files corresponding to each resource folder, and determining the resource files corresponding to all the resource folders as the resource files corresponding to the application program.
3. The method for detecting resource conflict according to claim 2, wherein the preset filtering rule is a filtering array length of resource files smaller than a preset value, and correspondingly, the filtering the resource files corresponding to the application program according to the preset filtering rule to obtain intermediate resource files corresponding to the application program includes:
determining the array length of each resource file corresponding to the application program;
and filtering the resource files with the array length smaller than a preset value in the resource files corresponding to the application program to obtain intermediate resource files corresponding to the application program.
4. The resource conflict detection method of claim 1, wherein the storage address is a storage address of the intermediate resource file in a resource folder.
5. The resource conflict detection method according to claim 1, wherein determining a current MD5 value of a current intermediate resource file corresponding to the current key and a target MD5 value of a target intermediate resource file corresponding to the target key comprises:
determining file contents of a current intermediate resource file corresponding to the current key and file contents of a target intermediate resource file corresponding to the target key;
After the file content of the current intermediate resource file is converted into a current byte array, determining a current MD5 value corresponding to the current byte array as a current MD5 value of the current intermediate resource file;
after the file content of the target intermediate resource file is converted into a target byte array, determining a target MD5 value corresponding to the target byte array as a target MD5 value of the target intermediate resource file.
6. The resource conflict detection method according to claim 5, wherein determining the file content of the current intermediate resource file corresponding to the current key and the file content of the target intermediate resource file corresponding to the target key includes:
and reading the file content of the current intermediate resource file corresponding to the current key and the file content of the target intermediate resource file corresponding to the target key from the hash table based on UTF-8 coding.
7. The method of claim 5, wherein determining the current MD5 value corresponding to the current byte array as the current MD5 value of the current intermediate resource file comprises:
after converting the current byte array into a current MD5 value byte array, converting the current MD5 value byte array into a current MD5 value, and determining the current MD5 value as the current MD5 value of the current intermediate resource file;
Determining the target MD5 value corresponding to the target byte array as the target MD5 value of the target intermediate resource file, including:
after the target byte array is converted into a target MD5 value byte array, the target MD5 value byte array is converted into a target MD5 value, and the target MD5 value is determined as the target MD5 value of the target intermediate resource file.
8. The resource conflict detection method according to claim 1, further comprising, after determining that there is a resource conflict between the current intermediate resource file and the target intermediate resource file:
and deleting the current intermediate resource file or the target intermediate resource file.
9. The resource conflict detection method of claim 1, further comprising:
and when the fact that the target key consistent with the current key does not exist in the hash table is determined, continuing to traverse the hash table.
10. The resource conflict detection method of claim 1, further comprising:
and when the current MD5 value is inconsistent with the target MD5 value, continuing to traverse the hash table.
11. A resource conflict detection apparatus, comprising:
the acquisition module is used for acquiring the resource file corresponding to the application program, and filtering the resource file corresponding to the application program according to a preset filtering rule to obtain an intermediate resource file corresponding to the application program;
The storage module is used for storing the intermediate resource file based on a hash table, wherein keys of the hash table are file names and storage addresses of the intermediate resource file, and values of the hash table are file contents of the intermediate resource file;
the traversal module is used for traversing the hash table, and determining a current MD5 value of a current intermediate resource file corresponding to a current key and a target MD5 value of a target intermediate resource file corresponding to a target key when the target key consistent with the current key of the current intermediate resource file exists in the hash table;
and the determining module is used for determining that the current intermediate resource file and the target intermediate resource file have resource conflict when the current MD5 value is consistent with the target MD5 value.
12. A server, the server comprising:
at least one processor; and a memory communicatively coupled to the at least one processor;
wherein the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the resource conflict detection method of any one of claims 1-10.
13. A storage medium containing computer executable instructions which, when executed by a computer processor, are for performing the resource conflict detection method of any of claims 1-10.
CN202310402160.8A 2023-04-14 2023-04-14 Resource conflict detection method, device, server and storage medium Pending CN116431241A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310402160.8A CN116431241A (en) 2023-04-14 2023-04-14 Resource conflict detection method, device, server and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310402160.8A CN116431241A (en) 2023-04-14 2023-04-14 Resource conflict detection method, device, server and storage medium

Publications (1)

Publication Number Publication Date
CN116431241A true CN116431241A (en) 2023-07-14

Family

ID=87093978

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310402160.8A Pending CN116431241A (en) 2023-04-14 2023-04-14 Resource conflict detection method, device, server and storage medium

Country Status (1)

Country Link
CN (1) CN116431241A (en)

Similar Documents

Publication Publication Date Title
US11036614B1 (en) Data control-oriented smart contract static analysis method and system
CN111680253B (en) Page application data packet generation method and device, computer equipment and storage medium
CN111240684B (en) Cutting method and device of JS codes, medium and electronic equipment
US10423474B2 (en) Performing diagnostic tracing of an executing application to identify suspicious pointer values
CN112733158B (en) Android system vulnerability detection method, electronic equipment and storage medium
CN114035805B (en) Transcoding method, device, medium and equipment for precompiled device
CN114610640B (en) Fuzzy test method and system for trusted execution environment of Internet of things
CN111240987B (en) Method and device for detecting migration program, electronic equipment and computer readable storage medium
CN111124541B (en) Configuration file generation method, device, equipment and medium
CN110727476B (en) Method, device, equipment and storage medium for generating authorization configuration file
US9064042B2 (en) Instrumenting computer program code by merging template and target code methods
CN112527302B (en) Error detection method and device, terminal and storage medium
CN116432185B (en) Abnormality detection method and device, readable storage medium and electronic equipment
CN116431241A (en) Resource conflict detection method, device, server and storage medium
CN113687880B (en) Method, device, equipment and medium for calling component
CN113190235B (en) Code analysis method and device, electronic terminal and storage medium
CN114968260A (en) Hybrid pre-compiling method and device, electronic equipment and storage medium
CN116795371A (en) Condition compiling method, device, equipment and medium
CN118151999A (en) Program detection method, device, electronic equipment and storage medium
CN114296705A (en) Application package generation method and device, electronic equipment and storage medium
CN116881129A (en) Method, device and computer readable medium for fast checking resource unreleased code
CN115114287A (en) Code index generation method, device, equipment and computer storage medium
CN113760396A (en) Application running method and device, electronic equipment and storage medium
CN117472425A (en) Resource processing method and device, readable medium and electronic equipment
CN117472381A (en) Method, device, equipment and storage medium for processing code of application

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination