Disclosure of Invention
The technical problem to be solved by the invention is to provide a file processing method, which can quickly and accurately process files with inconsistent and abnormal processing.
The invention also provides a file processing device which is used for ensuring the realization and the application of the method in practice.
A method of file processing, comprising:
responding to the checking instruction, and acquiring file directory information of the distributed program to be processed;
determining a file to be verified under the file directory information under the condition that the file directory information is consistent with standard file directory information corresponding to the distributed program to be processed;
judging whether the modification time of the file to be checked is consistent with the standard modification time corresponding to the file to be checked;
under the condition that the modification time of the file to be verified is inconsistent with the standard modification time, judging whether the file to be verified is a text type file or not;
under the condition that the file to be checked is a text type file, judging whether the check value of the file to be checked is consistent with the standard check value corresponding to the file to be checked;
comparing the file to be checked with a standard file corresponding to the file to be checked under the condition that the check value of the file to be checked is inconsistent with the standard check value;
and under the condition that the comparison between the file to be checked and the standard file does not pass, replacing the file to be checked with the standard file.
Optionally, the determining whether the check value of the file to be checked is consistent with the standard check value corresponding to the file to be checked includes:
under the condition that the file to be checked meets a preset fragmentation condition, segmenting the file to be checked to obtain each fragment; calculating a fragment check value of each fragment, and judging whether the fragment check value of each fragment is consistent with a pre-recorded standard fragment check value corresponding to the fragment;
and under the condition that the file to be checked does not meet the preset fragmentation condition, calculating the file check value of the file to be checked, and judging whether the file check value of the file to be checked is consistent with the pre-recorded standard file check value corresponding to the file to be checked.
Optionally, the comparing the file to be checked with the standard file corresponding to the file to be checked includes:
respectively preprocessing the file to be checked and the standard file to remove invalid information in the file to be checked and the standard file;
calculating the matching degree between the preprocessed file to be checked and the preprocessed standard file;
under the condition that the matching degree meets a preset matching degree threshold value, determining that the file to be verified passes the comparison with the standard file;
and under the condition that the matching degree does not meet a preset matching degree threshold value, determining that the comparison between the file to be checked and the standard file does not pass.
The method described above, optionally, further includes:
and under the condition that the file to be checked is not a text type file, if the check value of the file to be checked is inconsistent with the standard check value corresponding to the file to be checked, replacing the file to be checked with the standard file corresponding to the file to be checked.
The method described above, optionally, further includes:
and under the condition that the file directory information is inconsistent with standard file directory information corresponding to the distributed program to be processed, determining that the file directory information is abnormal, and outputting a part inconsistent with the standard file target information in the file directory information.
A document processing apparatus comprising:
the acquisition unit is used for responding to the verification instruction and acquiring file directory information of the distributed program to be processed;
the determining unit is used for determining the file to be verified under the file directory information under the condition that the file directory information is consistent with the standard file directory information corresponding to the distributed program to be processed;
the first judgment unit is used for judging whether the modification time of the file to be checked is consistent with the standard modification time corresponding to the file to be checked;
the second judging unit is used for judging whether the file to be checked is a text type file or not under the condition that the modification time of the file to be checked is inconsistent with the standard modification time;
the third judging unit is used for judging whether the check value of the file to be checked is consistent with the standard check value corresponding to the file to be checked or not under the condition that the file to be checked is a text type file;
the comparison unit is used for comparing the file to be checked with the standard file corresponding to the file to be checked under the condition that the check value of the file to be checked is inconsistent with the standard check value;
and the replacing unit is used for replacing the file to be checked by using the standard file under the condition that the comparison between the file to be checked and the standard file fails.
Optionally, the apparatus described above, wherein the third determining unit includes:
the first execution subunit is used for segmenting the file to be verified under the condition that the file to be verified meets a preset segmentation condition to obtain each segment; calculating the fragment check value of each fragment, and judging whether the fragment check value of each fragment is consistent with a pre-recorded standard fragment check value corresponding to the fragment;
and the second execution subunit is used for calculating the file check value of the file to be checked under the condition that the file to be checked does not meet the preset fragmentation condition, and judging whether the file check value of the file to be checked is consistent with the pre-recorded standard file check value corresponding to the file to be checked.
The above apparatus, optionally, the comparing unit includes:
the preprocessing subunit is used for respectively preprocessing the file to be checked and the standard file so as to eliminate invalid information in the file to be checked and the standard file;
the calculation subunit is used for calculating the matching degree between the preprocessed file to be checked and the preprocessed standard file;
the first determining subunit is configured to determine that the file to be verified passes the comparison between the standard file and the file to be verified when the matching degree meets a preset matching degree threshold;
and the second determining subunit is used for determining that the comparison between the file to be verified and the standard file does not pass under the condition that the matching degree does not meet a preset matching degree threshold value.
A storage medium comprising stored instructions, wherein when executed, the instructions control a device on which the storage medium is located to perform a file processing method as described above.
An electronic device comprising a memory, and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by the one or more processors to perform the file processing method as described above.
Compared with the prior art, the invention has the following advantages:
the invention provides a file processing method and device, a storage medium and electronic equipment, wherein the method comprises the following steps: responding to the checking instruction, and acquiring file directory information of the distributed program to be processed; determining a file to be verified under the file directory information under the condition that the file directory information is consistent with standard file directory information corresponding to the distributed program to be processed; judging whether the modification time of the file to be checked is consistent with the standard modification time corresponding to the file to be checked; under the condition that the modification time of the file to be checked is inconsistent with the standard modification time, judging whether the file to be checked is a text type file or not; under the condition that the file to be checked is a text type file, judging whether the check value of the file to be checked is consistent with the standard check value corresponding to the file to be checked; comparing the file to be checked with a standard file corresponding to the file to be checked under the condition that the check value of the file to be checked is inconsistent with the standard check value; and under the condition that the comparison between the file to be checked and the standard file is not passed, replacing the file to be checked with the standard file. By applying the method provided by the embodiment of the invention, the files with inconsistent and abnormal conditions can be quickly and accurately processed.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In this application, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
An embodiment of the present invention provides a file processing method, which may be applied to an electronic device, where a method flowchart of the method is shown in fig. 1, and specifically includes:
s101: and responding to the checking instruction, and acquiring the file directory information of the distributed program to be processed.
In this embodiment, the to-be-processed distributed program may be one or more of distributed programs that are deployed in advance.
Optionally, each to-be-processed distributed program has one file directory information.
S102: and under the condition that the file directory information is consistent with the standard file directory information corresponding to the distributed program to be processed, determining the file to be verified under the file directory information.
In this embodiment, the file target directory information may be compared with standard file directory information, where the standard file directory information may be collected in advance, the number of files to be verified under the file directory information is one or more, and the standard file directory information is recorded in a preset configuration file.
S103: judging whether the modification time of the file to be checked is consistent with the standard modification time corresponding to the file to be checked; if not, executing S104, if yes, executing S108.
In this embodiment, the modification time may be the last time the file to be verified changes, the standard modification time may be collected in advance, and the standard modification time is recorded in the preset configuration file.
S104: judging whether the file to be checked is a text type file or not; if yes, executing S105; if not, S109 is executed.
In this embodiment, the file to be checked may be one of a text type file and a non-text type file, and whether the file to be checked is a text type file may be determined according to a file suffix or a file content of the file to be checked.
S105: judging whether the check value of the file to be checked is consistent with the standard check value corresponding to the file to be checked; if not, executing S106, if yes, executing S108.
In this embodiment, the check value of the file to be checked may be calculated, and the algorithm used in calculating the check value to be checked may be, but is not limited to, an information digest algorithm such as MD5(Message-digest algorithm 5).
Optionally, the standard check value corresponding to the file to be checked may be collected in advance; under the condition that the file to be verified is the file of the type, the corresponding standard verification value can be each standard fragment verification value or a standard file verification value, and the standard verification value is recorded in a preset configuration file.
S106: and comparing the file to be checked with the standard file corresponding to the file to be checked under the condition that the check value of the file to be checked is inconsistent with the standard check value.
In this embodiment, the document to be checked and the standard document corresponding to the document to be checked may be compared in a strong text consistency manner.
S107: and under the condition that the comparison between the file to be checked and the standard file does not pass, replacing the file to be checked with the standard file.
In this embodiment, when the comparison between the file to be checked and the standard file fails, the file to be checked may be replaced by the standard file, and specifically, the file to be checked may be covered by the standard file.
S108: and determining that the file to be verified passes the verification.
S109: judging whether the check value of the file to be checked is consistent with the standard check value corresponding to the file to be checked, if so, executing S108; if not, go to S110.
S110: and replacing the file to be checked by using the standard file corresponding to the file to be checked.
In this embodiment, after the standard file is used to replace the file to be verified, the file modification time of the file to be verified can be updated in the configuration file.
By applying the method provided by the embodiment of the invention, the files with inconsistent and abnormal conditions can be quickly and accurately processed.
In an embodiment of the present invention, based on the foregoing implementation process, optionally, the process of determining whether the check value of the file to be checked is consistent with the standard check value corresponding to the file to be checked in S105 includes:
under the condition that the file to be verified meets a preset fragmentation condition, segmenting the file to be verified to obtain each fragmentation; calculating a fragment check value of each fragment, and judging whether the check value of each fragment is consistent with a pre-recorded standard fragment check value corresponding to the fragment;
and under the condition that the file to be checked does not meet the preset fragmentation condition, calculating the file check value of the file to be checked, and judging whether the file check value of the file to be checked is consistent with the pre-recorded standard file check value corresponding to the file to be checked.
In this embodiment, the fragmentation condition may be that the storage space capacity occupied by the file to be verified is greater than a preset threshold, and the file to be verified may be fragmented in a preset fragmentation manner to obtain a plurality of fragments when the file to be verified satisfies the fragmentation condition.
Optionally, when the check value of at least one fragment is inconsistent with the check value of the standard fragment corresponding to the fragment, it is determined that the check value of the file to be checked is consistent with the standard check value corresponding to the file to be checked, and when all the fragment check values are consistent with the corresponding standard fragment check values, it is determined that the check value of the file to be checked is inconsistent with the standard check value corresponding to the file to be checked.
Optionally, under the condition that the file verification value of the file to be verified is the standard file verification value corresponding to the file to be verified, it is determined that the verification value of the file to be verified is consistent with the verification value of the standard file.
In an embodiment of the present invention, based on the implementation process, optionally, the process of comparing the file to be checked with the standard file corresponding to the file to be checked, as shown in fig. 2, may include:
s201: and respectively preprocessing the file to be checked and the standard file to remove invalid information in the file to be checked and the standard file.
In this embodiment, the invalidation information may invalidate at least one of a trade line and an invalid space.
S202: and calculating the matching degree between the preprocessed file to be checked and the preprocessed standard file.
In this embodiment, a cosine distance algorithm or an edit distance algorithm may be used to calculate a matching degree between the file to be checked and the standard file, where the matching degree may represent a distance or a similarity between the file to be checked and the standard file, and the matching degree may range from 0 to 1, and the closer to 1, the more similar the two files are.
S203: and under the condition that the matching degree meets a preset matching degree threshold value, determining that the file to be verified and the standard file pass through comparison.
In this embodiment, the threshold of the matching degree may be 1, and when the matching degree is 1, it is determined that the file to be checked and the standard file pass through the comparison.
S204: and under the condition that the matching degree does not meet a preset matching degree threshold value, determining that the comparison between the file to be checked and the standard file does not pass.
In an embodiment provided by the present invention, based on the implementation process, optionally, the implementation process further includes:
and under the condition that the file directory information is inconsistent with standard file directory information corresponding to the distributed program to be processed, determining that the file directory information is abnormal, and outputting a part inconsistent with the standard file target information in the file directory information.
The method provided by the embodiment of the invention can be applied to the verification of the program files of various distributed programs. In the practical application process, referring to fig. 3, a flowchart of a file processing process provided in the embodiment of the present invention is shown, in which standard information is collected first, then information verification is initialized, and then daily information verification is performed.
In this embodiment, the process of collecting standard information is shown in fig. 4, a set of standard program directories may be selected from a plurality of sets of distributed programs, where the directory is an already-defined standard program directory, the program directory is used as a reference, the directory and all objects under the directory are traversed recursively, if the traversed and selected object is a link or a directory, the traversal is skipped directly, if the object is a file, it is determined whether the file is a text file, if the file is a non-text file, an MD5 hash value of the file is directly calculated, if the program file is a text file, the size of the file is obtained, and when the file exceeds a specified size, the file is sliced, and an MD5 value of each slice is recorded; the standard information may include MD5 values and file name and path information for the file.
After the standard information is collected, information verification is initialized, and as shown in fig. 5, each set of distributed programs to be compared may be compared with a standard program directory, a link and a file only compare a name, and a file compares an MD5 value or a fragment MD5 value thereof, and if the MD5 value or the fragment MD5 value is inconsistent, the target file is overwritten with the standard file. When the values of the MD5 of the file are the same, the modification information of the file and the value of the MD5 or the value of the slice MD5 are recorded in a local configuration file for the next time of comparison.
Further, after the initialized information is checked, performing daily information checking, as shown in fig. 6, performing distributed program checking by using a fast distributed program consistency checking method for daily information checking, performing consistency checking on the distributed program according to the comparison frequency required by the operation and maintenance staff, and comparing the contents of the program files. When comparing, firstly comparing directory structures to ensure the consistency of the directory structures of the files, then comparing the modification time of the files, if the modification time of the files is the initialized modification time of the local configuration files of the distributed program, directly judging that the files are not changed, if not, starting to compare the MD5 value or the slice MD5 value of the files, if the MD5 value or the slice MD5 value is consistent with the value recorded on the local configuration files, judging that the files are not changed, only modifying the modification time of the files in the local configuration files at the moment, if not, carrying out strong consistency check on the files, carrying out strong consistency check by adopting a format tower mode matching and an automatic garbage heuristic algorithm, processing each line of a standard text file and each line of a program to be compared, finding out the longest continuous matching sequence without garbage elements (empty lines and blank spaces), matching, and calculating the matching degree of the whole text, if the matching degree is 1, judging that the file is normal, only modifying the modification time of the file in the local configuration file, otherwise, judging that the text file automatically does not contain the step of identifying the file as an abnormal file, selecting a standard file for covering, and outputting abnormal information.
In this embodiment, to solve the problem of Hash collision of the MD5 algorithm and the problem of slow verification speed of the large text file MD5, the present invention provides a fast MD5 Hash algorithm, which divides a text file exceeding a certain size into one subfile every N rows, provides a multithreading technique, and calculates and compares Hash values of the fragmented MD5 files using multiple threads, and this algorithm makes full use of a multi-core server, thereby effectively increasing the calculation speed of the MD5, and at the same time, due to the adoption of the fragmentation technique, reduces a keyword set, further reduces an address set of information verified by the MD5, and reduces the probability of Hash collision of the MD5 algorithm.
In this embodiment, a strong consistency text matching algorithm based on a format tower mode is adopted, and the algorithm is a similarity calculation method used in this embodiment, and is used as a supplement method of an MD5 fragmentation algorithm, and is mainly used for removing and comparing junk added with invalid line feeds, spaces and the like in a text, and comparing files in an understandable way.
By applying the method provided by the embodiment, through a distributed program consistency verification method based on file modification time, a fragment MD5 algorithm and a strong consistency text matching algorithm, the speed is higher than that of the traditional single file MD5 algorithm, the time consumed by verification is reduced by about 50% when a quad-core server is used for verifying a large file actually, the fragment algorithm reduces the range of an address set input by the HASH algorithm to a certain extent, the probability of Hash collision is reduced, when all fragments are verified successfully, the algorithm judges that the files are the same file, the reliability of the MD5 algorithm is increased to a certain extent, besides the advantages, strong consistency comparison of the text is provided, after meaningless information such as invalid line change, blank space and the like in the text is removed, the text files are compared, and the similarity is calculated, so that whether the texts are consistent or not is confirmed.
Corresponding to the method illustrated in fig. 1, an embodiment of the present invention further provides a file processing apparatus, which is used for specifically implementing the method illustrated in fig. 1, where the file processing apparatus provided in the embodiment of the present invention may be applied to an electronic device, and a schematic structural diagram of the file processing apparatus is illustrated in fig. 7, and specifically includes:
an obtaining unit 701, configured to obtain, in response to the check instruction, file directory information of the to-be-processed distributed program;
a determining unit 702, configured to determine, when the file directory information is consistent with standard file directory information corresponding to the to-be-processed distributed program, a to-be-verified file under the file directory information;
a first determining unit 703, configured to determine whether the modification time of the file to be verified is consistent with a standard modification time corresponding to the file to be verified;
a second determining unit 704, configured to determine whether the file to be verified is a text type file when the modification time of the file to be verified is inconsistent with the standard modification time;
a third determining unit 705, configured to determine whether a check value of the file to be checked is consistent with a standard check value corresponding to the file to be checked when the file to be checked is a text-type file;
a comparing unit 706, configured to compare the to-be-checked file with a standard file corresponding to the to-be-checked file when the check value of the to-be-checked file is inconsistent with the standard check value;
a replacing unit 707, configured to replace the to-be-verified file with the standard file when the to-be-verified file does not pass the comparison with the standard file.
In an embodiment provided in the embodiment of the present invention, based on the above scheme, specifically, the third determining unit 705 includes:
the first execution subunit is used for segmenting the file to be verified under the condition that the file to be verified meets a preset segmentation condition to obtain each segment; calculating a fragment check value of each fragment, and judging whether the fragment check value of each fragment is consistent with a pre-recorded standard fragment check value corresponding to the fragment;
and the second execution subunit is used for calculating the file check value of the file to be checked under the condition that the file to be checked does not meet the preset fragmentation condition, and judging whether the file check value of the file to be checked is consistent with the pre-recorded standard file check value corresponding to the file to be checked.
In an embodiment of the present invention, based on the above scheme, specifically, the comparing unit 706 includes:
the preprocessing subunit is used for respectively preprocessing the file to be checked and the standard file so as to eliminate invalid information in the file to be checked and the standard file;
the calculation subunit is used for calculating the matching degree between the preprocessed file to be checked and the preprocessed standard file;
the first determining subunit is used for determining that the file to be verified passes the comparison between the file to be verified and the standard file under the condition that the matching degree meets a preset matching degree threshold;
and the second determining subunit is used for determining that the comparison between the file to be verified and the standard file does not pass under the condition that the matching degree does not meet a preset matching degree threshold value.
In an embodiment provided in the embodiment of the present invention, based on the above scheme, specifically, the file processing apparatus further includes:
and the execution unit is used for replacing the file to be checked with the standard file corresponding to the file to be checked if the check value of the file to be checked is inconsistent with the standard check value corresponding to the file to be checked under the condition that the file to be checked is not the text type file.
In an embodiment provided in the embodiment of the present invention, based on the above scheme, specifically, the file processing apparatus further includes:
and the output unit is used for determining that the file directory information is abnormal and outputting a part of the file directory information inconsistent with the standard file target information under the condition that the file directory information is inconsistent with the standard file directory information corresponding to the distributed program to be processed.
The specific principle and the execution process of each unit and each module in the file processing apparatus disclosed in the above embodiment of the present invention are the same as those of the file processing method disclosed in the above embodiment of the present invention, and reference may be made to corresponding parts in the file processing method provided in the above embodiment of the present invention, which are not described herein again.
The embodiment of the invention also provides a storage medium, which comprises stored instructions, wherein when the instructions are executed, the equipment where the storage medium is located is controlled to execute the file processing method.
An electronic device is provided in an embodiment of the present invention, and the structural diagram of the electronic device is shown in fig. 8, which specifically includes a memory 801 and one or more instructions 802, where the one or more instructions 802 are stored in the memory 801 and configured to be executed by the one or more processors 803 to perform the following operations:
responding to the checking instruction, and acquiring file directory information of the distributed program to be processed;
determining a file to be verified under the file directory information under the condition that the file directory information is consistent with standard file directory information corresponding to the distributed program to be processed;
judging whether the modification time of the file to be checked is consistent with the standard modification time corresponding to the file to be checked;
under the condition that the modification time of the file to be checked is inconsistent with the standard modification time, judging whether the file to be checked is a text type file or not;
under the condition that the file to be checked is a text type file, judging whether the check value of the file to be checked is consistent with the standard check value corresponding to the file to be checked;
comparing the file to be checked with a standard file corresponding to the file to be checked under the condition that the check value of the file to be checked is inconsistent with the standard check value;
and under the condition that the comparison between the file to be checked and the standard file does not pass, replacing the file to be checked with the standard file.
It should be noted that, in the present specification, the embodiments are all described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other. For the device-like embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in the process, method, article, or apparatus that comprises the element.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functions of the units may be implemented in the same software and/or hardware or in a plurality of software and/or hardware when implementing the invention.
From the above description of the embodiments, it is clear to those skilled in the art that the present invention can be implemented by software plus necessary general hardware platform. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which may be stored in a storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method according to the embodiments or some parts of the embodiments.
The above detailed description is provided for a file processing method provided by the present invention, and the principle and the implementation of the present invention are explained by applying specific examples, and the description of the above examples is only used to help understanding the method and the core idea of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, the specific embodiments and the application range may be changed, and in summary, the content of the present specification should not be construed as a limitation to the present invention.