Disclosure of Invention
The invention provides a method and a system for updating embedded file data, which are used for solving the defect that the embedded file is easy to have abnormal updating when the data is updated in the prior art.
In a first aspect, the present invention provides an embedded file data updating method, including:
after the system is initialized, running a selector to check the abstract digital directory to obtain a mapping path, and calling an application starting script under the mapping path to finish application starting;
and the application starting script calls a decompressor to run in the background to obtain an update package, and the update package is decompressed based on the abstract digital directory under an update path to finish data update.
According to the embedded file data updating method provided by the invention, after the system is initialized, a selector is operated to check an abstract digital directory to obtain a mapping path, and an application start script under the mapping path is called to complete application start, wherein the method comprises the following steps:
determining the number of the abstract digital catalogues in the updating path, and if only one abstract digital catalog exists, mapping the abstract digital catalog into the mapping path by the selector;
and if the updating path comprises a plurality of abstract digital directories, the selector extracts the abstract digital directories and sequences the abstract digital directories, and checks the check file in the maximum value directory to obtain the mapping path.
According to the embedded file data updating method provided by the invention, the verifying the verification file in the maximum value directory to obtain the mapping path comprises the following steps:
if the verification is successful, deleting the minimum value directory, and mapping the maximum value directory to be the mapping path by the selector;
otherwise, deleting the maximum value directory, and mapping the maximum value directory minus 1 to the mapping path by the selector.
According to the embedded file data updating method provided by the invention, the initial value of the updating path only comprises one directory, and the name of the initial value of the updating path is the preset abstract number minimum value.
According to the embedded file data updating method provided by the invention, the application startup script calls a decompressor to run in the background to obtain an update package, and the update package is decompressed based on the abstract digital directory under an update path to complete data updating, which comprises the following steps:
if the decompressor obtains no available updating data packet, the updating program is quitted;
and if the decompressor acquires that the available update data packet exists, acquiring the update packet, and decompressing by taking the maximum value directory plus 1 as the directory name under the update path.
According to the embedded file data updating method provided by the invention, if the file system is an unreliable log file system, the updating path is divided into an even updating path and an odd updating path;
the even update path is used for storing abstract even directories, and the odd update path is used for storing abstract odd directories.
In a second aspect, the present invention further provides an embedded file data updating system, including:
the selector module is used for running the selector to check the abstract digital directory to obtain a mapping path after the system is initialized, and calling an application starting script under the mapping path to finish application starting;
and the decompressor module is used for calling the decompressor to run in a background by the application starting script, acquiring an update package, decompressing the update package based on the abstract digital directory under an update path and finishing data update.
In a third aspect, the present invention further provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of any of the above embedded file data updating methods.
In a fourth aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the steps of the embedded file data updating method according to any one of the above.
In a fifth aspect, the present invention also provides a computer program product comprising a computer program, which when executed by a processor, implements the steps of the embedded file data updating method according to any one of the above.
According to the embedded file data updating method and system provided by the invention, the updating program is divided into two parts, namely the selector and the decompressor, by adding mathematical logic calculation on the basis of storing the updating file in the embedded file system, and the abnormality of the file system during updating iteration is avoided in a dynamic mapping mode, so that the sequence, compatibility and stability of the updating data are ensured.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is obvious that the described embodiments are some, but not all embodiments of the present invention. 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.
Fig. 1 is a schematic flow chart of an embedded file data updating method provided by the present invention, as shown in fig. 1, including:
step S1, after the system is initialized, operating a selector to check the abstract digital directory to obtain a mapping path, and calling an application start script under the mapping path to finish application start;
and step S2, the application startup script calls a decompressor to run in the background to obtain an update package, and the update package is decompressed based on the abstract digital directory under an update path to complete data update.
It can be understood that the present invention adds mathematical logic on the basis of the embedded file system storing the update file, and ensures the sequentiality and atomicity of the new and old replacements through digital calculation, i.e. ensures that a complete update process is visible and completely successful, or the update process is transparent and completely ineffective.
Specifically, the updating program is divided into two functional parts with complementary functions, one part realizes the fixed basic content as a system program part and is named as a selector CHOOSER, and the other part realizes the business logic content as an application program part and is named as a decompressor unparker. In the present invention, the execution items that both the selector CHOOSER and the decompressor unparker need to know and comply with are defined as a contract, which is a basic requirement for ensuring compatibility of the update procedure.
On the basis, the invention also introduces an abstract number naming and a mapping path, wherein the abstract number naming refers to that the name comprises any letter or number sequence which can be extracted according to convention, and satisfies the forms which can be compared, accumulated and have the minimum value; the mapping path refers to a link or reference to a certain path A and named as B, which is equivalent to an alias, and some file systems support the characteristic by themselves, and is called symbolic link, and in the unsupported file system, the mapping path can be indirectly realized by transferring dynamically generated character string path parameters to a function needing the path.
The update package downloaded in the updating process refers to a set of all updatable programs, libraries, driving modules, scripts, configurations and data, and has a directory structure organized according to convention after being expanded; a check file CHECKLST is stored in an update package root directory and is used for detecting the validity of all files in a package, and if the file does not exist after decompression due to any condition or the data of the file is referred to and does not accord with the check, all data packages are considered invalid; in addition, an application start script STARTAPP with a default name exists in the update package, system start ready is completed through calling of the script, and operation switching is performed to the application.
Specifically, after the embedded file system is initialized, the selector CHOOSER starts to operate, checks the abstract digital directory to obtain the mapping path, and further calls an application start script STARTAPP under the mapping path to complete application start. The application start script STARTAPP calls a decompressor unparker to run in the background, checks whether an update is available to obtain an update package, mathematically calculates the abstract digital directory on an update path UPATH to obtain a target digital directory, decompresses the update package under the directory, and executes an update program.
The relationship among the selector, decompressor, mapping link and abstract digital directory involved in the present invention is shown in fig. 2, the selector belongs to the system program, and in the firmware partition, it belongs to the non-updatable content; the decompressor belongs to an application program and belongs to updatable content in an abstract digital directory of a common partition; the abstract digital directory may contain a plurality of directories, but the mapping link only points to a valid and latest directory, the obsolete abstract digital directory is deleted by the selector, and the new abstract digital directory is generated by the decompressor.
According to the invention, mathematical logic calculation is added on the basis that the embedded file system stores the update file, the update program is divided into two parts with complementary functions of the selector and the decompressor, and the file system is prevented from being abnormal during update iteration in a dynamic mapping mode, so that the sequence, compatibility and stability of the update data are ensured.
Based on the above embodiment, after the system is initialized, the operating selector checks the abstract digital directory to obtain the mapping path, and invokes the application start script under the mapping path to complete application start, including:
determining the number of the abstract digital directories in the updating path, wherein if only one abstract digital directory exists, the selector maps the abstract digital directory to be the mapping path;
and if the updating path comprises a plurality of abstract digital directories, the selector extracts the abstract digital directories and sequences the abstract digital directories, and checks the check file in the maximum value directory to obtain the mapping path.
The verifying the check file in the maximum value directory to obtain the mapping path includes:
if the verification is successful, deleting the minimum value directory, and mapping the maximum value directory to be the mapping path by the selector;
otherwise, deleting the maximum value directory, and mapping the maximum value directory minus 1 to the mapping path by the selector.
Specifically, after the system is initialized, the selector CHOOSER checks the update path update, establishes an agreed mapping path REAL to point to the selected abstract digital directory, and all applications can only see the mapping path REAL, which is transparent to the digital path where the applications are located.
Checking the number of the abstract digital directories, if the update path UPATH only has one abstract digital directory, directly mapping the directory to REAL by a selector CHOOSER, avoiding detection to accelerate the common starting process, and here, simply deriving to prove that the directory is completely checked before; if the update path UPATH includes more than one abstract number directory, the selector CHOOSER extracts the abstract numbers of the directories and sorts the abstract numbers, verifies the verification file CHECKLST of the maximum MAX directory, if the verification passes, deletes the minimum MIN directory first, and then maps the maximum MAX directory as the mapping path REAL, otherwise, deletes the maximum MAX directory first and then maps the maximum MAX-1 as the mapping path REAL, and similarly, it can be proved through simple derivation that when the maximum MAX is incomplete, MAX-1 must exist and the verification is complete, and the execution flow of the corresponding selector CHOOSER is shown in fig. 3.
It should be noted that the activity of the selector CHOOSER is not disturbed by external factors, repeatedly interrupts its process, and has no influence on its operation result, and after several starts, the number of directories under the update path UPATH will be converged into one, which can be proved by simple derivation to be the latest sequence in the complete and effective update package. After the mapping path REAL is established, the selector CHOOSER hands over the control right to the application layer according to the appointed calling application start script STARTAPP, and the decompressor unparker belongs to the common application program called by the application start script STARTAPP, so that the selector CHOOSER and the decompressor unparker do not add and delete the digital directory under the update at the same time, and do not generate mutual interference. The selector CHOOSER is realized by belonging to a part of a system program, is not updated, only completes the conventional inherent function, scans an abstract digital directory on an update path UPATH, calculates a check value, clears a eliminated directory, maps an effective directory, and calls an application start script STARTAPP, and the operation ensures the basic update compatibility.
The invention avoids the vulnerability of the file system in the atom switching process by adopting a dynamic mapping mode, separates the main compatibility logic in the updating process into a selector CHOOSER as a firmware part, and ensures the compatibility and the stability of the updating process.
Based on any of the above embodiments, the initial value of the update path only includes one directory, and the name of the initial value of the update path is the preset abstract number minimum value.
Specifically, the update path UPATH referred to in the present invention is agreed, and as the file system is just shipped, there is only one directory under the path, and the name of the directory is the minimum value of the agreed abstract number, and the hierarchical structure of the directory and the update package are completely consistent, so the directory must be completely verified before shipping.
The invention avoids the possible confusion in the edition updating iteration in the forms of abstract digital calculation and integral verification, strictly ensures the sequence, ensures that the system cannot be substantially damaged by external impacts such as accidental power failure and the like through special design, and ensures that any external influence is transparent to all application programs.
Based on any of the above embodiments, the application startup script invokes the decompressor to perform background operation to obtain the update package, and decompresses the update package based on the abstract digital directory in the update path to complete data update, including:
if the decompressor obtains no available updating data packet, the updating program is quitted;
and if the decompressor acquires that the available update data packet exists, acquiring the update packet, and decompressing by taking the maximum value directory plus 1 as the directory name under the update path.
Specifically, as shown in fig. 4, the update package is configured to be downloaded only by the decompressor unparker, and is expanded under the update path UPATH by using the abstract number containing the convention rule as the directory name, and the value is the maximum value MAX of the abstract number accumulated by one under the update path UPATH. The single start of the decompressor unparker only runs once, that is, at most, a directory is newly added under the update path UPATH, and the start of the decompressor unparker is only responsible for decompressing and expanding the update packet, and is not responsible for the completeness of the data of the update packet after decompression, after all, the process termination can be caused by accidents at any time during the decompression process.
The method comprises the steps that a to-be-applied starting script STARTAPP calls a decompressor UNPACKER to run in a background, available updates are checked, the realization of the decompressor UNPACKER belongs to a part of an application program, only one convention needs to be decompressed under an update path UPATH, the update can be continuously performed by self, and the sufficient degree of freedom of product function expansion is ensured.
In the updating process, the main transactional logic is separated into a decompressor UNPACKER as an application part, so that the freedom and the expandability of an updating mode are ensured; meanwhile, the system has self-cleaning capability, and can continuously clean invalid garbage of the system, including normally eliminated files and data, and also including updated defective goods generated by accidents, so that the system is constantly kept in an updated state.
Based on any of the above embodiments, if the file system is an unreliable journaling file system, dividing the update path into an even update path and an odd update path;
the even update path is used for storing abstract even directories, and the odd update path is used for storing abstract odd directories.
Optionally, if the file system does not belong to a reliable journaling file system, the update path UPATH may be split into an UPATH _ EVEN (EVEN number) and an UPAHT _ ODD (ODD number) in separate partitions, and only the abstract EVEN directory and the abstract ODD directory are expanded and placed, respectively, and due to the accumulative replacement, both are not destroyed at the same time and can be repaired in a format.
The above-mentioned arrangement shows that the rules proposed by the present invention are strict, the structure is clear, and the verification and implementation are easy, for example, the workload of compiling codes for completing the selector CHOOSER and the decompressor PACKER by using SHELL scripts in the embedded LINUX system is only about one hundred lines, and the present invention is particularly suitable for updating low-cost products and quickly forming schemes.
The embedded file data updating system provided by the invention is described below, and the embedded file data updating system described below and the embedded file data updating method described above can be referred to correspondingly.
Fig. 5 is a schematic structural diagram of an embedded file data updating system provided by the present invention, as shown in fig. 5, including: a selector module 51 and a decompressor module 52, wherein:
the selector module 51 is configured to, after the system is initialized, run a selector to check the abstract digital directory to obtain a mapping path, and call an application start script under the mapping path to complete application start; the decompressor module 52 is configured to invoke the decompressor to perform background operation by the application start script, acquire an update packet, decompress the update packet based on the abstract digital directory in an update path, and complete data update.
According to the invention, mathematical logic calculation is added on the basis that the embedded file system stores the update file, the update program is divided into two parts with complementary functions of the selector and the decompressor, and the file system is prevented from being abnormal during update iteration in a dynamic mapping mode, so that the sequence, compatibility and stability of the update data are ensured.
Based on the above embodiment, the selector module 51 includes: a determination sub-module 511 and a decision sub-module 512, wherein:
the determining submodule 511 is configured to determine the number of the abstract digital directories in the update path, and if there is only one abstract digital directory, the selector maps the abstract digital directory to the mapping path; the judgment sub-module 512 is configured to, if the update path includes a plurality of abstract digital directories, extract the plurality of abstract digital directories and sort the abstract digital directories, check a check file in a maximum value directory, and obtain the mapping path.
The judgment sub-module 512 is specifically configured to:
if the verification is successful, deleting the minimum value directory, and mapping the maximum value directory to be the mapping path by the selector; otherwise, deleting the maximum value directory, and mapping the maximum value directory minus 1 to the mapping path by the selector.
Based on any of the above embodiments, the initial value of the update path only includes one directory, and the name of the initial value of the update path is the preset abstract number minimum value.
Based on any of the above embodiments, the decompressor module 52 includes: a first decompression submodule 521 and a second decompression submodule 522, wherein:
the first decompression sub-module 521 is configured to exit the update procedure if the decompressor obtains no available update data packet; the second decompressing submodule 522 is configured to, if the decompressor obtains that there is an available update packet, obtain the update packet, and decompress the update packet by using the maximum directory plus 1 as the directory name in the update path.
Based on any of the above embodiments, the system further includes a path updating module 53, where the path updating module 53 is configured to:
if the file system is an unreliable log file system, dividing the updating path into an even updating path and an odd updating path; the even update path is used for storing abstract even directories, and the odd update path is used for storing abstract odd directories.
Fig. 6 illustrates a physical structure diagram of an electronic device, which may include, as shown in fig. 6: a processor (processor)610, a communication Interface (Communications Interface)620, a memory (memory)630 and a communication bus 640, wherein the processor 610, the communication Interface 620 and the memory 630 communicate with each other via the communication bus 640. The processor 610 may call logic instructions in the memory 630 to perform an embedded file data update method comprising: after the system is initialized, running a selector to check the abstract digital directory to obtain a mapping path, and calling an application starting script under the mapping path to finish application starting; and the application starting script calls a decompressor to run in the background to obtain an update package, and the update package is decompressed based on the abstract digital directory under an update path to finish data update.
In addition, the logic instructions in the memory 630 may be implemented in software functional units and stored in a computer readable storage medium when the logic instructions are sold or used as independent products. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
In another aspect, the present invention also provides a computer program product, the computer program product including a computer program, the computer program being stored on a non-transitory computer-readable storage medium, wherein when the computer program is executed by a processor, a computer is capable of executing the embedded file data updating method provided by the above methods, and the method includes: after the system is initialized, running a selector to check the abstract digital directory to obtain a mapping path, and calling an application starting script under the mapping path to finish application starting; and the application starting script calls a decompressor to run in the background to obtain an update package, and the update package is decompressed based on the abstract digital directory under an update path to finish data update.
In yet another aspect, the present invention also provides a non-transitory computer-readable storage medium, on which a computer program is stored, the computer program being implemented by a processor to perform the embedded file data updating method provided by the above methods, the method including: after the system is initialized, running a selector to check the abstract digital directory to obtain a mapping path, and calling an application starting script under the mapping path to finish application starting; and the application starting script calls a decompressor to run in the background to obtain an update package, and the update package is decompressed based on the abstract digital directory under an update path to finish data update.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable 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 methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.