Skip to content

Commit

Permalink
fix: in windows getObjects return absolute path to file including dri…
Browse files Browse the repository at this point in the history
…ve and dir instead of relative
  • Loading branch information
agolybev committed Sep 3, 2015
1 parent 08569f8 commit e3a3c50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/file-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,17 @@ var FileStore = function (rootDirectory) {

var getObjects = function (bucket, options, done) {
var bucketPath = getBucketPath(bucket.name);
var bucketPathWithSep = path.join(bucketPath, '/');
var replaceSeparator = '/' !== path.sep;
var matches = [];
var keys = utils.walk(bucketPath);
var filteredKeys = _.filter(keys, function (file) {
if (options.prefix) {
var key = file.replace(bucketPath + '/', '');
var key = file.replace(bucketPathWithSep, '');
if(replaceSeparator){
key = key.replace(new RegExp(utils.escapeRegExp(path.sep), 'g'), '/');
}
//expect options.prefix use '/' separator
var match = (key.substring(0, options.prefix.length) === options.prefix);
return match;
}
Expand All @@ -106,7 +112,11 @@ var FileStore = function (rootDirectory) {
async.eachSeries(filteredKeys, function (key, callback) {
fs.readFile(path.join(key, METADATA_FILE), function (err, data) {
if (data) {
matches.push(buildS3ObjectFromMetaDataFile(key.replace(bucketPath + '/', ''), data));
var outputKey = key.replace(bucketPathWithSep, '');
if(replaceSeparator){
outputKey = outputKey.replace(new RegExp(utils.escapeRegExp(path.sep), 'g'), '/');
}
matches.push(buildS3ObjectFromMetaDataFile(outputKey, data));
}
callback(null);
});
Expand Down
4 changes: 4 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ exports.walk = function (dir) {

return results;
};
// Gathered from http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript
exports.escapeRegExp = function (string) {
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
};

0 comments on commit e3a3c50

Please sign in to comment.