Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up spaces in var folder if using sample database #115

Open
juancarlosfarah opened this issue Jun 21, 2019 · 2 comments
Open

clean up spaces in var folder if using sample database #115

juancarlosfarah opened this issue Jun 21, 2019 · 2 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@juancarlosfarah
Copy link
Member

When selecting the sample database, we only use a space that is fully stored in the database. So all of the space folders inside the VAR_FOLDER should be removed. Currently we are keeping them, which means that the folder might keep accumulating unused spaces.

@juancarlosfarah juancarlosfarah added help wanted Extra attention is needed good first issue Good for newcomers labels Jun 21, 2019
@ansarkmemon
Copy link

Hey @juancarlosfarah I would love to help you out with this..just not sure I understand the issue exactly. Do you mind elaborating more on this?

@juancarlosfarah
Copy link
Member Author

Hi @amoury, thanks for your interest. Basically, we currently have two layers that deal with persistence:

  1. A database handled by lowdb.
  2. The file system, which is handled by electron, with everything inside the VAR_FOLDER path.

To use the sample database, the setDatabase action creator (in actions/developer.js) is called, which then calls the following method in the electron.js file:

  // called when setting the database
  ipcMain.on(SET_DATABASE_CHANNEL, async (event, payload) => {
    try {
      // get space from local db
      db.setState(payload).write();
      const database = db.getState();

      mainWindow.webContents.send(SET_DATABASE_CHANNEL, database);
    } catch (err) {
      logger.error(err);
      mainWindow.webContents.send(SET_DATABASE_CHANNEL, null);
    }
  });

The problem is that setDatabase overrides the database with whatever the database variable contains, which is usually an array under the key spaces and an object under the key user (An example can be seen in sample.json. What is does not do is free up the VAR_FOLDER, which contains a directory per space.

A first step would be to enhance the code above to get a list of the folders inside VAR_FOLDER. These folders have the name of the id property of the space. So then we can compare that list, with the ids of the space array in the database variable and then use rimraf to remove any folder that is not present in the space array.

Does that make sense? Thanks again for helping out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants