UNPKG

als-store

Version:

Library for streamlined file management and advanced data caching, featuring intelligent file searching, dynamic cache control, and flexible file operations

30 lines (23 loc) 2.19 kB
### Method: `renameDir(oldDirName, newDirName)` #### Overview: The `renameDir` method in the `Store` class is used for renaming a directory within the store. It allows for the modification of directory names, providing flexibility in managing the directory structure. #### Usage with `dir` Method: - **Setting Directory Path**: The `renameDir` method can be preceded by the `dir` method to specify the path to the directory that is to be renamed. - **Example**: ```js store.dir('some/path/to/dir').renameDir('old-value', 'new-value'); ``` #### Functionality: - **Directory Existence Check**: Before renaming, the method checks for the existence of both the old directory (to ensure it exists) and the new directory (to ensure it does not already exist). - **Renaming Process**: If the checks pass, the method proceeds to rename the old directory to the new directory name. - **Cache Update**: After renaming, the store's internal cache is updated to reflect the change in directory name. This ensures that subsequent operations on the store will recognize the new directory structure. #### Method Implementation: - **Parameters**: - `oldDirName` (String, required): The current name of the directory to be renamed. - `newDirName` (String, required): The new name for the directory. - **Asynchronous Operation**: The renaming operation is asynchronous, allowing other processes to run concurrently without blocking. - **Error Handling**: If either directory does not meet the existence criteria, the method will not proceed with the renaming to prevent any unintended data loss or conflicts. #### Important Notes: - **Correct Usage**: It's essential to ensure that the directory names provided are accurate and that the new directory name does not conflict with any existing directory names. - **Impact on Store**: Renaming a directory will affect all files and subdirectories within it. Users should be cautious to avoid disrupting the file structure unintentionally. This `renameDir` method provides an efficient way to manage the directory structure within the `Store` class, with built-in checks and cache updating for consistency and safety.