Virtual file management method, system and equipment and storage medium

By categorizing system paths into virtual paths based on business modules within the mobile application, the problem of inconsistent file directory structures was solved, achieving unified file management and improving file management efficiency and user experience.

CN121166645APending Publication Date: 2025-12-19GUANGZHOU NETSTAR INFORMATION TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202511290527.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-10
Publication Date
2025-12-19

AI Technical Summary

Technical Problem

In mobile applications, because each business module designs its own file paths and directory structure, the internal file directory structure of the application is inconsistent, resulting in directory structure fragmentation and arbitrary naming, which increases the complexity of maintenance and management and affects the user experience.

Method used

By mapping the system paths for storing target files to virtual paths according to the paths of business modules, and managing system file access through virtual paths, unified file management for different business modules within the application is achieved.

Benefits of technology

It improved the efficiency of file management across different business modules, reduced maintenance costs, and enhanced the effectiveness of application services and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121166645A_ABST
    Figure CN121166645A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a virtual file management method, system and device and a storage medium. According to the technical scheme provided by the embodiment of the invention, under the condition that the file request is received, the virtual path contained in the file request is extracted, the virtual path is created when the target file is generated, path classification is performed according to the module identifier of the associated target service module, and the target file is stored in the system path mapped by the virtual path. The system path is generated by mapping based on the virtual path and a pre-constructed mapping rule; mapping the virtual path into a corresponding system path based on a mapping rule; and accessing the target file based on the system path to execute a file operation corresponding to the file request. By means of the technical means, the situation that file directory structures of different service modules are disordered can be avoided, unified file management of the different service modules in the application is achieved, the file management efficiency of the different service modules is improved, the application service effect is improved, and therefore the user experience is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the technical field of computer technology, and particularly relate to a virtual file management method, system, device and storage medium. BACKGROUND

[0002] Currently, in mobile application development, a single application usually adopts a sandbox mechanism (a security mechanism that provides an isolated environment for a running program) for file management. It defines file storage directory structures such as Documents, Library, Caches and tmp in the system, which are respectively used to store persistent data, reproducible cache and temporary files. With the continuous improvement of business complexity, a single application often carries multiple functional modules. For example, in a comprehensive application, it may contain chat, video, live broadcast, music and other businesses at the same time. When each business module executes a related file request operation, it often directly uses a system interface to design a file path, organize a directory structure and implement cache cleaning logic, so as to implement a file request operation of the corresponding file path.

[0003] However, since each business module usually independently designs a file path and a directory structure, it leads to non-uniformity of the file directory structure inside the application, and easily causes directory structure fragmentation and random naming. For example, the chat module may cache voice to Library / Caches / IM / audio, while the video module caches similar cache to Documents / Video / Cache, and some functions mistakenly store temporary files in Documents instead of tmp. This leads to confusion in application file management, increases the complexity of subsequent maintenance and management, and further affects the application business service effect, resulting in poor user experience. SUMMARY

[0004] Embodiments of the present application provide a virtual file management method, system, device and storage medium, which maps a system path of a storage target file to a virtual path according to a path of a business module, and manages access to a system file through the virtual path, so as to avoid confusion of file directory structures of different business modules, and solve the technical problem of non-uniformity of file directory structures inside the application. Compared with the existing application internal file management method, the present application can implement unified file management of different business modules inside the application, improve the file management efficiency of different business modules, improve the application business service effect, and thus improve the user experience.

[0005] In a first aspect, embodiments of the present application provide a virtual file management method, comprising: In a case where the file request is received, the virtual path contained in the file request is extracted, the virtual path is created when the target file is generated, and the path is classified according to the module identifier of the target service module associated with the virtual path, the target file is stored in a system path mapped by the virtual path, and the system path is generated based on the virtual path and a pre-constructed mapping rule; The virtual path is mapped into a corresponding system path based on the mapping rule. The target file is accessed based on the system path, so as to perform a file operation corresponding to the file request.

[0006] In a second aspect, an embodiment of the present application provides a virtual file management system, comprising: A path extraction module configured to extract a virtual path contained in a file request in a case where the file request is received, the virtual path being created when a target file is generated and classified according to a module identifier of a target service module associated with the virtual path, the target file being stored in a system path mapped by the virtual path, the system path being generated based on the virtual path and a pre-constructed mapping rule; A path mapping module configured to map the virtual path into a corresponding system path based on the mapping rule. A file access module configured to access the target file based on the system path, so as to perform a file operation corresponding to the file request.

[0007] In a third aspect, an embodiment of the present application provides a virtual file management device, comprising: A memory and one or more processors; The memory is configured to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the virtual file management method according to the first aspect.

[0008] In a fourth aspect, an embodiment of the present application provides a nonvolatile computer readable storage medium, which stores computer executable instructions, and the computer executable instructions are configured to perform the virtual file management method according to the first aspect when executed by a computer processor.

[0009] In a fifth aspect, an embodiment of the present application provides a computer program product, which contains instructions, and when the instructions are executed on a computer or a processor, the computer or the processor performs the virtual file management method according to the first aspect.

[0010] The embodiment of the present application extracts the virtual path contained in the file request when receiving the file request, the virtual path is created when the target file is generated, and the virtual path is classified according to the module identifier of the associated target service module, the target file is stored in the system path mapped by the virtual path, and the system path is mapped and generated based on the virtual path and the pre-constructed mapping rule; the virtual path is mapped into the corresponding system path based on the mapping rule; the target file is accessed based on the system path to perform the file operation corresponding to the file request. By using the above technical means, the system path storing the target file is mapped into the virtual path according to the path classification of the service module, and the access of the system file is managed through the virtual path, so that the file directory structure confusion of different service modules is avoided, the unified file management of different service modules in the application is realized, the file management efficiency of different service modules is improved, the application service effect is improved, and the user experience is improved. BRIEF DESCRIPTION OF DRAWINGS

[0011] Figure 1 is a flowchart of a virtual file management method provided by the embodiment of the present application; Figure 2 is a virtual file directory schematic diagram in the embodiment of the present application; Figure 3 is a mapping flowchart of the system path in the embodiment of the present application; Figure 4 is a generation flowchart of the second sub-path in the embodiment of the present application; Figure 5 is a mapping schematic diagram of the virtual path and the system path in the embodiment of the present application; Figure 6 is a file cleaning flowchart in the embodiment of the present application; Figure 7 is a structure schematic diagram of a virtual file management system provided by the embodiment of the present application; Figure 8 is a structure schematic diagram of a virtual file management device provided by the embodiment of the present application. DETAILED DESCRIPTION

[0012] In order to make the purposes, technical solutions and advantages of the present application clearer, specific embodiments of the present application are further described in detail below in conjunction with the drawings. It can be understood that the specific embodiments described herein are only used to explain the present application, but not to limit the present application. In addition, it should be noted that, for the convenience of description, only parts related to the present application are shown in the drawings, but not all. Before discussing the example embodiments in more detail, it should be mentioned that some example embodiments are described as processes or methods depicted as flowcharts. Although the flowchart describes each operation (or step) as a sequential process, many of the operations can be implemented in parallel, concurrently or simultaneously. In addition, the order of the operations can be rearranged. The process can be terminated when its operations are completed, but can also have additional steps not included in the drawings. The process can correspond to a method, function, procedure, subroutine, etc.

[0013] The virtual file management method provided by the present application aims to map the system path of the storage target file according to the path classification of the business module as a virtual path, and manage the access of the system file through the virtual path, so as to realize the unified file management of different business modules in the application.

[0014] In the mobile application development scenario, with the continuous improvement of business complexity, a single application often carries multiple function modules. For example, in a comprehensive application, it may contain chat, video, live broadcast, music and other businesses at the same time. These business modules are usually responsible by different teams or subsystems, and their development cycle and technical scheme are independent.

[0015] When performing file management, the system provides standard file operation interfaces and defines file storage directory structures (such as Documents, Library, Caches, tmp, etc.) under the sandbox mechanism. These directories are open to individual applications, but the system does not provide a unified business-level file management solution. In actual development, each business module often directly uses the system interface to design file paths, organize directory structures and implement cache cleaning logic. In the absence of unified guidance, this approach gradually exposes the following problems: 1. Each business module implements the file system, resulting in chaotic directory structure. Different business lines freely organize file directory structures according to their own needs, for example: the chat module stores voice cache in Library / Caches / chat / audio / ; the video module caches video in Documents / videos / ; some functions mistakenly store temporary files in Documents instead of tmp. This decentralized management approach makes the overall project file structure complex and opaque, with high maintenance costs.

[0016] 2. File storage logic is repeatedly implemented, and there is a lot of redundant code. Due to the lack of unified file system abstraction, different business modules often repeatedly write the following logic: file saving logic (path splicing, file writing), file reading logic (path parsing, error handling), cache cleaning logic (time, size, expiration), file migration logic (path change when version is updated or refactored). These functions appear in multiple modules in their own implementation, resulting in inconsistent code style, complex testing, and increased fault risks and maintenance costs.

[0017] 3. File usage is scattered in each module for statistics, and each module stores files in different ways. This results in the inability to obtain the actual storage usage of each business, and the lack of disk usage analysis by directory or business dimension. In addition, the file cleaning strategy is scattered, and some directories are not clear, resulting in disk full, application system forced kill or refusal to write. Uncontrollable storage space exacerbates the instability of user experience, especially in low storage devices.

[0018] Therefore, a virtual file management method is provided in the embodiments of the present application to solve the technical problem of inconsistent file directory structure within an application.

[0019] Embodiments: Figure 1 A flowchart of a virtual file management method provided by the embodiments of the present application is given. The virtual file management method provided in the embodiments can be executed by a virtual file management device, which can be implemented by software and / or hardware. The virtual file management device can be composed of two or more physical entities, or one physical entity. Generally, the virtual file management device can be a computer, a mobile phone, a tablet, or the like.

[0020] The following describes the virtual file management device as an example of the main body for executing the virtual file management method. Referring to Figure 1 , the virtual file management method specifically includes: S110, in the case of receiving a file request, extracting a virtual path contained in the file request, the virtual path being created when a target file is generated, and classified according to a module identifier of an associated target business module, the target file being stored in a system path mapped by the virtual path, the system path being generated based on the virtual path and a pre-constructed mapping rule.

[0021] In the virtual file management process of the present application, when a file request is received, the virtual path contained therein is first extracted. The virtual path is classified and created according to the module identifier of the business module to which it belongs when the target file is generated. Its structure has consistency and business relevance, thereby avoiding the naming confusion and directory fragmentation problem caused by different modules defining paths themselves.

[0022] Specifically, the virtual file management framework is divided into interface layer, path layer and management layer, which are responsible for external file access, path mapping and underlying file resource management, respectively, so as to realize a highly modular, extensible and business decoupled file system management system in a sandbox environment, and improve the development efficiency and running reliability of large-scale applications in file resources.

[0023] Among them, the interface layer is mainly used to provide standardized file operation capability to the outside. For different business modules of an application, the file requests of the system file are received and processed through the interface layer. The interface layer encapsulates the extension of commonly used system classes and provides file access support under the virtual path. The interface layer integrates the native system operation interface and the virtual path mechanism, which can perform file reading and writing without sensing the real system path, thereby reducing the business access cost.

[0024] The path layer is used to abstract and encapsulate the representation, resolution and conversion of the virtual path, establish a stable mapping relationship between the virtual path and the actual system path, and provide consistent path access capability to the upper interface layer. This layer includes the following components: VFSPathRepresentable: defines the path representation protocol, and any path object (such as String, URL, VFSURL) that complies with the protocol can be used for access and operation of the virtual file system.

[0025] VFSURL: a path type customized by the present application, which encapsulates the core information of the virtual path, including root directory identifier, business module name, relative path and other attributes, and supports mutual conversion with system URL (Uniform Resource Address) type; VFSPathResolver: path resolver, responsible for converting the input virtual path into the corresponding real system path, and performing legality verification, path normalization and other operations during the resolution process; VFSSearchDirectory: virtual path root directory enumeration, including Documents, Caches and tmp, which corresponds one-to-one with the real system path directory enumeration, used to limit the legality of the virtual path starting point, and guarantee system safety and consistency.

[0026] The path layer ensures that the business module can complete all read and write operations through the virtual path when accessing the file system, avoiding direct reference to the system path, thereby achieving the purpose of logical isolation and controllable path.

[0027] The management layer is responsible for providing life cycle management of various file resources in the virtual path, including statistics, cleaning, migration, directory tree and other functions, to support the maintainability and evolvability of the system. Its core modules include: VFSMetric: File statistics module, collecting file disk occupancy size and directory size by business dimension, used for file storage size analysis; VFSMigration: File migration module and file path mounting module, supporting automatic migration of historical files to new virtual path structure when application version is upgraded or module structure is adjusted, to avoid data loss or path failure; VFSCleaner: Cleaning module, providing cache cleaning capability by module or path, which can be used for application automatic cleaning of useless resources; VFSTree / VFSTreeManager: Virtual file tree and its manager, used for building, traversing, and operating the entire virtual file structure, supporting quick positioning, enumeration, and grouping operations by module.

[0028] The management layer can manage the stability, operation and maintenance efficiency, and data controllability of the file system through centralized management strategies, and is especially suitable for application projects with a large number of modules and complex life cycles.

[0029] Further, based on the above virtual file management framework, a unified virtual path specification can be established to realize unified management and structured organization of system files of different business modules in the application. As shown in Figure 2 The virtual file takes "VFS / " as the root directory, builds a directory system corresponding to the real system file directory structure, and introduces a business module dimension for sub-path division.

[0030] Among them, in order to realize the abstract management of the system path, the present application defines VFSPathRepresentable as the path representation protocol, and any path object (such as String or URL) conforming to the protocol can realize virtual file management. The variables of the protocol include: vfs_path: path actual value, type is string (String); isVirtualPath: represents whether it is a virtual path, used for virtual path legality verification. The verification rule is as follows: judge whether the vfs_path starts with the virtual path root directory ("VFS / Documents", "VFS / tmp", "VFS / Caches"). For example, "VFS / Documents / Story" is a virtual path because it starts with the virtual directory root directory. For example, "var / mobile / Containers" is not a virtual path because it does not start with the virtual directory root directory; vfs_url: convert object to VFSURL type, VFSURL type is a virtual path interface created by the application, which is a URL type for system path interface. VFSURL type itself follows the VFSPathRepresentable protocol. The initialization of VFSURL interface is to pass in a path of string type; url: convert object to URL type, which is a convenient interface for converting virtual paths to system paths.

[0031] In the operating system, the application runs in a separate sandbox mechanism environment, and its file system structure mainly includes three root directories: 1. Library / Caches: used for caching data, which will be deleted by the system when the device space is tight. 2. Documents: used for storing user data, long-term storage. 3. tmp: temporary file, which may be cleaned up by the system at any time. In order to ensure the consistency and standardization of the virtual path construction, the application defines an enumeration type VFSSearchPathDirectory of virtual directory, which includes three common root directories corresponding to the virtual root directories of Documents, Caches and tmp.

[0032] The enumeration type VFSSearchPathDirectory has a one-to-one correspondence with the standard enumeration type NSSearchPathDirectory provided by the system path interface. Among them: VFSSearchPathDirectory.Documents corresponds to the system enumeration NSSearchPathDirectory.documentDirectory of the real system path interface; VFSSearchPathDirectory.Caches corresponds to the system enumeration NSSearchPathDirectory.cachesDirectory of the real system path interface VFSSearchPathDirectory.tmp corresponds to the system enumeration NSTemporaryDirectory() of the real system path interface.

[0033] Through this design, the system business layer can only rely on this uniform enumeration type when performing file path splicing, resource positioning and cache management, so as to accurately map the system path.

[0034] For example, the virtual path "VFS / Caches" can be obtained through the virtual path interface VFSSearchPathDirectory.Caches. Based on the VFSSearchPathDirectory enumeration, the system service layer can construct the path based on the explicit directory semantics when performing virtual path splicing and resource location, thereby avoiding inconsistencies and maintenance difficulties caused by hard-coded path strings. This enumeration type not only provides explicit identification of path semantics, but also makes the path construction process more type-safe and readable.

[0035] It can be understood that in the operating system, all storage and reading operations of persistent or temporary data ultimately rely on real system paths (i.e., absolute paths of URL or String type) to complete underlying file system access. Therefore, in order to shield the underlying path implementation details and improve the standardization and maintainability of path usage, the present application further constructs a virtual path mapping mechanism for converting a logical virtual path into a system-actually-recognizable physical path, i.e., a system path.

[0036] The virtual path mapping mechanism is undertaken by the class VFSPathResolver, and its path resolution process follows the following steps: 1. Input the file path, and determine whether the current file path is a virtual path according to the protocol VFSPathRepresentable isVirtualPath. If not, return empty and end the process; 2. In the case where the file path is determined to be a virtual path, generate the root directory of the real path according to the pre-constructed correspondence between the virtual path root directory and the real path root directory: a. If the virtual path has VFS / Documents / as the root directory, the real path root directory is: var / mobile / Containers / Data / Application / <uuid> / Documents / vfs / b. If the virtual path has a root directory of VFS / Caches / , the real path root directory is: var / mobile / Containers / Data / Application / <uuid> / Library / Caches / vfs / c. If the virtual path has a root directory of VFS / tmp / , the real path root directory is: var / mobile / Containers / Data / Application / <uuid> / tmp / vfs / Except for the prefix part of the virtual path root directory, the remaining part of the file will be processed by the path level. Each level of sub-path is split by the path separator " / " and the hash (such as SHA256 hash operation) operation is performed on each level of directory name, so as to generate a secure and unpredictable actual storage path, that is, a system path.

[0037] Based on the above-mentioned constructed virtual directory, virtual path and unified directory specification, the unified management of the file directory structure among multiple service modules can be realized. After a certain service module completes file creation, the file virtual path can be created according to the module identification, file type and other information of the service module, and the real system path is determined according to the mapping mechanism of the virtual path and the system path, so as to store the file to the system path. When a target service needs to operate a target file corresponding to the system path, the virtual path in the file request is parsed, the real system path is determined through the virtual path, and the target file corresponding to the system path is accessed through the virtual path.

[0038] Optionally, the application also implements a virtual path management mechanism based on a tree structure. The core of the mechanism is jointly borne by the VFSTree and the manager VFSTreeManager, which is used to simulate the hierarchical structure of the real file system and to structure and dynamically manage the virtual path through the multi-way tree model.

[0039] Among them, VFSTree represents a virtual path structure, which is used to describe the basic structure of the virtual path hierarchical relationship and is implemented by a multi-way tree model. Each node VFSTreeNode of VFSTree corresponds to a segment (i.e. a level directory or a file name) in the virtual path, which can be regarded as a logical expression of a segment of the path. Each VFSTreeNode node contains the following core fields: name: represents the name of the current path node (type of string), which is used to express the readability of the logical path, such as "user", "profile" and the like; hashKey: the hash value corresponding to the name of the node, which is usually generated by SHA256 algorithm, and is used to generate unpredictable directory names in the real path structure, so as to improve the security and isolation of the path; children: a collection of child nodes (stored in an array structure), which is used to describe the child path mounted under the path node, so as to facilitate the traversal of the tree structure and the child path search.

[0040] Through the structure, each level of directory of the virtual path can be abstracted as a node, and the system can maintain the structure and state of the entire virtual path space by adding and deleting nodes.

[0041] VFSTreeManager represents the path tree manager, which is used for centralized management of registration, query, and change of the path tree. The VFSTreeManager class is introduced as the management hub of the path tree. The main responsibilities include: initialization and persistence of the path tree structure, registration of virtual path nodes (if the path does not exist, the hierarchical creation is automatically performed), and provision of path search, node traversal, and path disassembly functions.

[0042] Exemplarily, when a file is written or created through a virtual path, the VFSTreeManager automatically triggers the registration interface to register the virtual path; when a file is deleted through a virtual path, the VFSTreeManager automatically triggers the deletion interface to delete the virtual path. Through the above interfaces, the system can efficiently perform the parsing process from the virtual path string to the path node, and realize flexible directory management and file-level operations.

[0043] Optionally, the virtual file management method of the present application further comprises: re-encapsulating the system class method of the operating system path, to operate the virtual path based on the re-encapsulated system class method.

[0044] Without changing the original system class method calling rule, the present application re-encapsulates the following key classes through the Category method: 1. FileManager+VFS The system FileManager class is extended to support the execution of standard file operations through a virtual path, including the creation, deletion, copying, moving, and enumeration traversal of files and directories. All path parameters are mapped to the corresponding system path through the VFSPathResolver.

[0045] b. Data+VFS The virtual path read-write capability of the system Data type is provided. Arbitrary binary data (such as cache, download resource, and media stream) can be written into a virtual path, and Data instances can also be efficiently read from a virtual path.

[0046] c. AVAssetWriter+VFS In the system AVFoundation framework, the initialization and resource writing capability of AVAssetWriter are extended, so that developers can directly specify a virtual path for media resource (such as audio and video) export and persistent storage.

[0047] d. NSFileHandle+VFS Support to obtain file handle object NSFileHandle through virtual path, for low-level file read and write, streaming access, offset control and other scenarios, to adapt to high-level file operation requirements.

[0048] e.NSArray+VFS / NSDictionary+VFS Extend the object archiving and dearchiving functions of NSArray and NSDictionary, allowing structured data to be persisted through virtual paths (supporting JSON, Plist, and other formats), for typical scenarios such as configuration items, cache dictionaries, and model serialization.

[0049] By re-encapsulating the original system class method, the interface is translated, so that while fully retaining the system class method, the business logic does not need to be aware of the underlying path change, and the support of the virtual path by the business logic is realized.

[0050] S120、Based on the mapping rule, the virtual path is mapped to the corresponding system path.

[0051] Further, based on the above virtual file path mapping mechanism, when determining the virtual path of the target file, the virtual path can be converted to the system path where the target file is actually stored according to the predefined mapping rule. The mapping rule explicitly defines the correspondence between the virtual path structure and the actual file system directory, thereby realizing the standardization and centralized management of the directory structure at the physical storage level, and avoiding the problem of arbitrary selection of storage location by different modules.

[0052] Specifically, referring to Figure 3 , the virtual path is mapped to the corresponding system path based on the mapping rule, including: S1201, parsing the first root directory and the first sub-path of the virtual path; S1202, mapping the first root directory to the second root directory based on the enumeration type correspondence set in the mapping rule; S1203, hashing the first sub-path to the second sub-path based on the hash algorithm set in the mapping rule; S1204, concatenating the second root directory and the second sub-path to obtain the system path.

[0053] In the path mapping process, first, the virtual path is parsed, and the root directory of the virtual path prefix part can be split out through the above-mentioned preset virtual path root directory, defined as the first root directory, and the remaining part is the first sub-path.

[0054] Further, according to the correspondence relationship of the predefined root directory enumeration type, the first root directory of the virtual path can be mapped to the actual path root directory conforming to the system specification, defined as the second root directory. For the first sub-path part of the virtual path, a hash operation is performed through a preset hash algorithm, and the hash value obtained by the operation represents the second sub-path.

[0055] Specifically, referring to Figure 4 , the first sub-path is mapped to the second sub-path based on the hash algorithm set in the mapping rule, including: S12031, in the case that the first sub-path includes multiple hierarchical directories, the first sub-path is segmented into path segments according to the hierarchical relationship of the multiple hierarchical directories; S12032, the hash value of each path segment is calculated based on the set hash algorithm; S12033, the calculated hash values are spliced according to the hierarchical relationship of the multiple hierarchical directories to generate the second sub-path.

[0056] It can be understood that the first sub-path includes multiple directory information separated by path levels, so for multiple hierarchical directories, each level of sub-path needs to be split into path segments by the path separator " / ", and then a hash (such as SHA256 hash operation) operation is performed on each level of path segment (i.e. the directory name corresponding to the directory level) to obtain the hash value representing the directory name of the level. Further, the hash values are re-spliced according to the hierarchical relationship of the original multiple hierarchical directories using the separator " / " to obtain the second sub-path.

[0057] The mapping relationship between the virtual path and the system path is shown in Figure 5 Finally, the second root directory after mapping and the second sub-path are spliced to generate the final system path that can be directly accessed by the operating system.

[0058] For example, for the virtual path: VFS / Documents / user / avatar / image.png, the mapping of the root directory VFS / Documents / is based on the pre-constructed correspondence relationship, which is mapped to the real path root directory var / mobile / Containers / Data / Application / <uuid> / Documents / vfs / . Further, for the sub-path user / avatar / image.png part, it is split into 1, user is mapped to SHA256(user), 2, avatar is mapped to SHA256(avatar), and 3, image.png is mapped to SHA256(image.png). The final generated real system path is represented as: / var / mobile / ... / Documents / vfs / 3c7e1a... / 9a4f11... / d4g56h.... S130, accessing the target file based on the system path to perform a file operation corresponding to the file request.

[0059] Then, the target file is accessed by the system path obtained by mapping, and an operation corresponding to the file request is performed, such as reading, writing, or deleting. Since all business modules access files through the unified virtual path mechanism, the organization and flexibility of the internal file system of the application are improved, the maintenance cost and performance risk on the user side caused by file management chaos are reduced, the file management efficiency of different business modules is improved, and thus the application business service effect is improved, and the user experience is improved.

[0060] Optionally, the application further introduces a path-level statistics, cleaning, and migration mechanism on the basis of the path tree management mechanism, which is used to implement on-demand monitoring, directional recycling, and path reconstruction operations on virtual paths and their corresponding physical files. The following basic metadata is maintained at the VFSTreeNode level: diskSize: disk occupied space (unit: byte); contentAccessDate: last access time, maintained by VFSTreeManager. Whenever a virtual path file is read, VFSTreeManager automatically updates the last access time of the node.

[0061] The core class of virtual path storage statistics is VFSMetric, which recursively counts the resource occupation of all virtual path nodes based on the multi-ary tree structure of VFSTree. The storage statistics logic of VFSMetric is as follows: 1. Depth-first traversal of VFSTree, starting from the root node of the virtual path tree (such as VFS / Documents / ), using traversal, accessing each VFSTreeNode node one by one.

[0062] 2. Determine whether the children attribute is empty a. If the children of the current node is empty, it means that the node is a leaf node, which may represent a specific file resource or an empty directory; b. At this time, the corresponding system path is calculated according to the path mapping rule, and it is checked whether the file or directory exists; c. If the file exists, its disk size is obtained (the underlying API is called to calculate the file size), and the diskSize field of the current node is updated; d. If the file does not exist, skip or record an exception to avoid counting false data.

[0063] 3. If the children is not empty, recursively process all child nodes a. Repeat steps 1-2 for each child node, and aggregate the statistical results of all child nodes to the current parent node: currentNode.diskSize = sum(child.diskSize) b. Through this recursive aggregation method, the total resource occupation corresponding to any path node can be quickly obtained.

[0064] Further, with reference to Figure 6 , the virtual file management method of the present application further comprises: S1401, when the storage data of the target directory reaches the set space upper limit, determining the corresponding system path based on each virtual path contained in the target directory; S1402, performing file cleaning according to the determined system path, so that the storage data of the target directory is lower than the set value.

[0065] To realize the automatic management and resource recycling of the virtual path space, the present application designs and implements an automatic cleaning mechanism based on access time priority on the basis of the virtual path management framework. The mechanism is responsible for specific execution by the core class VFSCleaner, and relies on the storage statistics, path structure and file operation capabilities provided by VFSMetric, VFSTree and VFSManager to realize on-demand cleaning for virtual paths.

[0066] VFSCleaner receives the following parameters when initializing: a. Virtual path prefix: define the path root node of the cleaning range (such as VFS / Documents / user / avatar / ), and the cleaning is only performed under this subtree; b. Disk occupation upper limit T (Threshold): in bytes, define the maximum disk space that the current path can accommodate; c. Clean target ratio R (Ratio): a decimal between 0 and 1, defining the reserved ratio when triggering cleaning, i.e. the desired compression of disk occupancy to T x R.

[0067] Based on the above settings, when it is detected that the storage data of the target directory reaches the set upper limit of space (i.e. the upper limit of disk occupancy T), file cleaning is triggered so that the storage data of the target directory reaches the desired target ratio R.

[0068] Specifically, file cleaning is performed according to the determined system path, including: The last access time of each virtual path contained in the target directory is determined, the corresponding system paths are sorted based on the order of the last access time, and file cleaning of the system paths is performed in sequence according to the sorting result.

[0069] In the case where it is determined that the storage data of the target directory reaches the set upper limit of space, first enter the VFSTree of the target directory, recursively traverse all VFSTreeNode nodes under the path of the target directory, extract the last access time contentAccessDate attribute, and sort in ascending order according to the time (i.e. the earlier the access time, the higher the priority). Then, according to the sorting result, the sub-nodes are cleaned in sequence from front to back, the real path is found through the virtual path of the node, and the related files are deleted in the file system. The cleaning process continues until the current disk occupancy is less than or equal to the target threshold T_target (i.e. T x R) or all cleanable nodes are traversed.

[0070] Exemplarily, assuming that the disk upper limit T of the corresponding target directory is 100MB and the cleaning ratio R is 0.6 (i.e. the target is compressed to 60MB). When the target directory occupies 120MB of space, the system will automatically trigger the cleaning process and try to recycle the resources under the path to less than or equal to 60MB, only retaining the recently accessed active resources.

[0071] In addition, optionally, the present application also introduces a path migration mechanism to support the complete migration of data under a certain virtual path to another target path, and simultaneously updates the structure mapping and real path location in the virtual path tree. The mechanism is undertaken by the core class VFSMigration to perform specific execution duties, responsible for path data migration scheduling, node remapping, and path data consistency verification operations, etc.

[0072] Wherein, the following parameters need to be specified when VFSMigration is initialized: Source virtual path: the root path of the data to be migrated, such as VFS / Documents / user / avatar / ; Target virtual path: the path target after migration, such as VFS / Documents / profile / image / The migration logic of VFSMigration includes the following core steps: a. Path legality verification Determine whether the source virtual path and the target virtual path are both valid virtual paths (determined by the protocol VFSPathRepresentable), and ensure that they do not form a circular dependency relationship or path conflict.

[0073] b. System path conversion and detection Call VFSPathResolver to map the source virtual path and the target virtual path to real system paths respectively, and verify whether the files under the source virtual path exist.

[0074] c. File-level copying and relocation Traverse all files and subdirectory structures under the source virtual path, copy the physical files to the target virtual path using deep copy method, and delete the resources in the source virtual path after copying is completed to complete the migration operation.

[0075] d. Meta information migration Carry the metadata of the source virtual path (such as diskSize, contentAccessDate) to the target virtual path to ensure consistency in structure and attributes.

[0076] The path migration mechanism implemented by VFSMigration can support dynamic path reconstruction, adapt to complex business path structure change requirements, and synchronize data copying and path registration to ensure consistency of system structure and data logic before and after migration.

[0077] Optionally, the virtual file management method of the present application further comprises: Determine the historical files that already exist in memory and have not constructed virtual paths, and mount the system paths of the historical files to the corresponding virtual paths based on the set path mapping table, so as to access the historical files through the mounted virtual paths.

[0078] Before using the virtual path framework of the present application for virtual file management, there are a large number of historical files inside the application, and the system paths of these files have been fixed. Based on the file path mounting mechanism, the present application associates the existing system paths with the virtual path system, so that they are uniformly included in the virtual path management framework.

[0079] Among them, any existing system path is mounted to a specified virtual path node. Through path mounting, a set of path mapping tables are maintained at the bottom layer, so that the same file resource can be accessed through the following three paths: a. original real system path (e.g. / var / mobile / Containers / ... / OldStorage / image.jpg); b. mapped virtual path (e.g. VFS / Documents / user / avatar / image.jpg); c. new system path resolved by virtual path (e.g. / var / mobile / Containers / ... / Documents / vfs / xxx / yyy / zzz.jpg).

[0080] The specific file mounting path reading and writing logic is as follows: (1) input virtual path; (2) obtain the real path through the virtual path mapping mechanism, if it is found that a file already exists in the corresponding position, return the file. This situation indicates that the original file has been migrated. If the file does not exist, proceed to step (3).

[0081] (3) determine whether the virtual path exists for mounting mapping, if not, the file does not exist, and reading fails. If it exists, proceed to step (4); (4) if the mounting mapping already exists, automatically fall back to the original real system path for resource access. If the file exists, return the file. Otherwise, it indicates that the file does not exist, and file reading fails.

[0082] By introducing the path mounting mechanism, historical files, external folders and third-party module data can be seamlessly integrated into the virtual path system without modifying the original file location; and regardless of the original location of the resource, the business layer can access through the virtual path, maintaining code consistency, and breaking down the isolation between the real system path and the virtual path, realizing system path compatibility and logical path unification, The virtual file management system provided in the present application comprises a path extraction module 21, a path mapping module 22 and a file access module 23.

[0083] On the basis of the above-mentioned embodiments, Figure 7 A structural schematic diagram of a virtual file management system provided in the present application is shown in FIG. 1. Figure 7 The virtual file management system provided in the present embodiment specifically comprises a path extraction module 21, a path mapping module 22 and a file access module 23.

[0084] The path extraction module 21 is configured to extract a virtual path contained in a file request in the case of receiving the file request, the virtual path being created at the time of generation of a target file and classified according to a module identifier of an associated target service module, the target file being stored in a system path mapped by the virtual path, the system path being generated based on the virtual path and a pre-constructed mapping rule. The path mapping module 22 is configured to map the virtual path into a corresponding system path based on the mapping rule. The file access module 23 is configured to access the target file based on the system path to perform a file operation corresponding to the file request.

[0085] Specifically, the virtual file management system further comprises: The system class method of the operating system path is re-encapsulated to operate the virtual path based on the re-encapsulated system class method.

[0086] Specifically, mapping the virtual path into the corresponding system path based on the mapping rule comprises: analyzing a first root directory and a first sub-path of the virtual path; mapping the first root directory into a second root directory based on a corresponding relationship of an enumeration type set in the mapping rule; hashing mapping the first sub-path into a second sub-path based on a hash algorithm set in the mapping rule; splicing the second root directory and the second sub-path to obtain the system path.

[0087] The first sub-path is hashed and mapped to the second sub-path based on a hash algorithm set in the mapping rule, including: In the case where the first sub-path includes multiple hierarchical directories, the first sub-path is segmented into path segments according to the hierarchical relationship of the multiple hierarchical directories; The hash values of the path segments are calculated based on the set hash algorithm; The calculated hash values are spliced according to the hierarchical relationship of the multiple hierarchical directories to generate the second sub-path.

[0088] Specifically, the virtual file management system further includes: When it is detected that the storage data of the target directory reaches a set upper limit of space, the corresponding system path is determined based on each virtual path contained in the target directory; According to the determined system path, file cleaning is performed to make the storage data of the target directory lower than the set value.

[0089] According to the determined system path, file cleaning is performed to make the storage data of the target directory lower than the set value. The last access time of each virtual path contained in the target directory is determined, the corresponding system paths are sorted according to the order of the last access time, and the file cleaning of the system paths is performed in sequence according to the sorting result.

[0090] Specifically, the virtual file management system further includes: The history files that already exist in the memory and have not been constructed into virtual paths are determined, and the system paths of the history files are mounted to the corresponding virtual paths based on the set path mapping table, so that the history files can be accessed through the mounted virtual paths.

[0091] The above, by extracting the virtual path contained in the file request when receiving the file request, the virtual path is created when the target file is generated, and the path is classified according to the module identifier of the associated target business module, the target file is stored in the system path mapped by the virtual path, and the system path is generated based on the virtual path and the pre-constructed mapping rule; the virtual path is mapped to the corresponding system path based on the mapping rule; the target file is accessed based on the system path to perform the file operation of the corresponding file request. By using the above technical means, the system path storing the target file is mapped to the virtual path according to the path classification of the business module, and the system file is accessed through the virtual path, so as to avoid the case that the file directory structure of different business modules is chaotic, realize the unified file management of different business modules in the application, improve the file management efficiency of different business modules, improve the application business service effect, and thus improve the user experience.

[0092] The virtual file management system provided by the embodiments of the present application can be configured to execute the virtual file management method provided by the above embodiments, and has corresponding functions and beneficial effects.

[0093] Based on the actual examples described above, the embodiments of the present application further provide a virtual file management device, which is described with reference to Figure 8 The virtual file management device includes a processor 31, a memory 32, a communication module 33, an input device 34, and an output device 35. The memory 32 is a computer readable storage medium, which can be configured to store software programs, computer executable programs, and modules, such as program instructions / modules corresponding to the virtual file management method described in any of the embodiments of the present application (for example, a path extraction module, a path mapping module, and a file access module in the virtual file management system). The communication module 33 is configured to perform data transmission. The processor 31 executes various functional applications and data processing of the device by running the software programs, instructions, and modules stored in the memory, that is, implements the virtual file management method described above. The input device 34 can be configured to receive input digital or character information, and generate key signal inputs related to user settings and function control of the device. The output device 35 can include a display device such as a display screen. The virtual file management device provided above can be configured to execute the virtual file management method provided by the above embodiments, and has corresponding functions and beneficial effects.

[0094] Based on the above embodiments, the embodiments of the present application further provide a non-volatile computer readable storage medium, which stores computer executable instructions. The computer executable instructions are configured to execute a virtual file management method when executed by a computer processor. The storage medium can be any of various types of memory devices or storage devices. Of course, the computer executable instructions of the non-volatile computer readable storage medium provided by the embodiments of the present application are not limited to the virtual file management method described above, but can also execute related operations in the virtual file management method provided by any of the embodiments of the present application.

[0095] Based on the above embodiments, the embodiments of the present application further provide a computer program product. The technical solutions of the present application essentially or the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer program product is stored in a storage medium and includes a plurality of instructions for causing a computer device, a mobile terminal, or a processor therein to execute all or part of the steps of the virtual file management method described in the embodiments of the present application.< / uuid> < / uuid> < / uuid> < / uuid>

Claims

1. A virtual file management method, characterized in that, include: Upon receiving a file request, the virtual path contained in the file request is extracted. The virtual path is created when the target file is generated, and the path is classified according to the module identifier of the associated target business module. The target file is stored in the system path mapped by the virtual path. The system path is generated based on the virtual path and pre-built mapping rules. Based on the mapping rules, the virtual path is mapped to the corresponding system path; Access the target file based on the system path to perform the file operation corresponding to the file request.

2. The virtual file management method according to claim 1, characterized in that, The step of mapping the virtual path to the corresponding system path based on the mapping rules includes: Parse the first root directory and first subpath of the virtual path; Based on the enumeration type correspondence set in the mapping rules, the first root directory is mapped to the second root directory; The first sub-path is hash-mapped to the second sub-path based on the hash algorithm set in the mapping rules. The system path is obtained by concatenating the second root directory and the second subpath.

3. The virtual file management method according to claim 2, characterized in that, The hash mapping of the first sub-path to the second sub-path based on the hash algorithm set in the mapping rule includes: If the first sub-path includes multiple levels of directories, the first sub-path is divided into path segments according to the hierarchical relationship of the multiple levels of directories; The hash value of each path segment is calculated based on the set hash algorithm; The hash value calculated by concatenating the hierarchical relationships of multiple directories is used to generate the second sub-path.

4. The virtual file management method according to any one of claims 1-3, characterized in that, The method further includes: The system class methods that operate on the system path are re-encapsulated so that the virtual path can be operated based on the re-encapsulated system class methods.

5. The virtual file management method according to any one of claims 1-3, characterized in that, The method further includes: If the storage data in the target directory reaches the set space limit, the corresponding system path is determined based on each of the virtual paths contained in the target directory; File cleanup is performed based on the determined system path to reduce the stored data in the target directory to a set value.

6. The virtual file management method according to claim 5, characterized in that, The process of cleaning up files based on the determined system path includes: The last access time of each virtual path contained in the target directory is determined, and the corresponding system paths are sorted according to the order of the last access times. The files of the system paths are cleaned up in sequence according to the sorting results.

7. The virtual file management method according to any one of claims 1-3, characterized in that, The method further includes: If a historical file exists in memory but has not yet been constructed using the virtual path, the system path of the historical file is mounted to the corresponding virtual path based on a set path mapping table, so that the historical file can be accessed through the mounted virtual path.

8. A virtual file management system, characterized in that, include: The path extraction module is configured to extract the virtual path contained in the file request when a file request is received. The virtual path is created when the target file is generated and is classified according to the module identifier of the associated target business module. The target file is stored in the system path mapped by the virtual path. The system path is generated based on the virtual path and pre-built mapping rules. The path mapping module is configured to map the virtual path to the corresponding system path based on the mapping rules. The file access module is configured to access the target file based on the system path in order to perform file operations corresponding to the file request.

9. A virtual file management device, characterized in that, include: Memory and one or more processors; The memory is configured to store one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the virtual file management method as described in any one of claims 1-7.

10. A non-volatile computer-readable storage medium, characterized in that, The non-volatile computer-readable storage medium stores computer-executable instructions that, when executed by a computer processor, are configured to perform the virtual file management method as described in any one of claims 1-7.

11. A computer program product, characterized in that, The computer program product includes instructions that, when executed on a computer or processor, cause the computer or processor to perform the virtual file management method as described in any one of claims 1-7.

Citation Information

Cited By

  • Virtual consistency multi-node message passing interface expansion method, device and equipment

    CN121530967A

  • Method, apparatus and device for virtual consistent multi-node message passing interface extension

    CN121530967B