Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Snapshot directories by traversing root nodes recursively #4

Merged
merged 3 commits into from
Mar 24, 2022

Conversation

nizarmah
Copy link
Owner

Description

This pull request implements the ability to "snapshot" directories.

The node program records the tree structure (files and sub-directories) of each directory passed as a parameter.

The directories passed as parameters are considered root nodes, and then the program recursively traverses each node and defines its children, which traverses each child and defines the child's children, and so on...

By doing so, we record the entire tree, from each directory.

We store that information in memory, as cache. This allows us to instantly return the entire tree, instead of computing it again and again.

Testing

  • Set up the server
  • Run the server with the following command with the directories you'd like included
npm run debug ~/Documents ~/Downloads ...
  • Navigate to http://localhost:3000 and make sure the JSON data matches your file directories

Notes

This change can be optimized in the future.

Imagine passing two directories as parameters, one is ~/A and the other is ~/A/B.

At the moment, the program traverse both ~/A and ~/A/B. However, we're traversing ~/A/B twice.

This can be optimized by using memoization. That way we wouldn't have to re-traverse ~/A/B. Instead, we can just point towards that Node.

Creates a tree node which recursively collects the children it has, if it's a directory
Takes directory paths as arguments, which are then considered root nodes and traversed recursively to collect the entire tree structure, including sub directories

The root nodes collected, along with their children, are then returned as a json response

Also this change adds a new debugging script which shows debugging console logs
@nizarmah
Copy link
Owner Author

LGTM 👍🏼

@nizarmah nizarmah merged commit 6ba4bff into main Mar 24, 2022
@nizarmah nizarmah deleted the feature/snapshot-directories branch March 24, 2022 01:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant