groovebasin/lib/safe_path.js
Andrew Kelley 5c8f45b6e9 improve import by URL feature. closes #171
* Drop dependency on temp module
 * Download files to music-folder/.tmp/ before moving them.
 * Don't watch folders that start with a '.'
 * Don't allow generated paths to start with a '.'

Fixes import file race condition.

Prevents needless file copy operation when importing in situations where
the music directory is in a different device than /tmp.
2014-03-26 17:17:07 -07:00

11 lines
265 B
JavaScript

module.exports = safePath;
var MAX_LEN = 100;
function safePath(string) {
string = string.replace(/[<>:"\/\\|?*%]/g, "_");
string = string.substring(0, MAX_LEN);
string = string.replace(/\.$/, "_");
string = string.replace(/^\./, "_");
return string;
}