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

Allow absolute paths in db name #13

Open
cintolas opened this issue Oct 24, 2018 · 0 comments
Open

Allow absolute paths in db name #13

cintolas opened this issue Oct 24, 2018 · 0 comments

Comments

@cintolas
Copy link

LocalStorageCore does not allow a user to specify an absolute path.
The issue comes from the fact that sanitizeFilename strips the root separator making everything relative to the current directory.

When using pouchdb-adapter-fs this has the effect that the prefix writes everything to the current directory instead of writing from the root directory

I patched my project with a 1 line fix

function LocalStorageCore(dbname) {
  var self = this;
/* One line patch.  Check if the first character is a '/' and append it */
  var filename = (dbname [0] === path.sep ? path.sep : '') + path.join.apply(null, dbname.split(path.sep).map(sanitizeFilename)) + '.json';
/* End patch */
  if (dbs.has(dbname)) {
    self._db = dbs.get(dbname);
  } else {
    mkdirp.sync(path.dirname(filename));
    self.import(dbname, filename);
  }

I wonder if you have a better solution for this?
The sanitize-filename module by definition gets rid of all the path stuff. Optimally it would be nice to be able to set an option to ignore the sanitize and just pass it in as is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant