Skip to content

Commit

Permalink
Merge pull request #1070 from noobaa/guy_fix_list_objects
Browse files Browse the repository at this point in the history
fix list objects with delimiter vs prefix to also honor just prefix (and not kill the entire bucket)
  • Loading branch information
guymguym committed Apr 20, 2016
2 parents e7a22f3 + 03525f3 commit d2ba040
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/server/object_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,18 +539,18 @@ var ONE_LEVEL_SLASH_DELIMITER = one_level_delimiter('/');
function list_objects(req) {
dbg.log0('list_objects', req.rpc_params);
var prefix = req.rpc_params.prefix || '';
var delimiter = req.rpc_params.delimiter;
let escaped_prefix = string_utils.escapeRegExp(prefix);
var delimiter = req.rpc_params.delimiter || '';
load_bucket(req);
return P.fcall(() => {
var info = _.omit(object_md_query(req), 'key');
var common_prefixes_query;

if (!_.isUndefined(delimiter)) {
if (delimiter) {
// find objects that match "prefix***" or "prefix***/"
var one_level = delimiter && delimiter !== '/' ?
let one_level = delimiter !== '/' ?
one_level_delimiter(delimiter) :
ONE_LEVEL_SLASH_DELIMITER;
var escaped_prefix = string_utils.escapeRegExp(prefix);
info.key = new RegExp('^' + escaped_prefix + one_level);

// we need another query to find common prefixes
Expand All @@ -577,6 +577,8 @@ function list_objects(req) {
inline: 1
}
});
} else if (prefix) {
info.key = new RegExp('^' + escaped_prefix);
} else if (req.rpc_params.key_query) {
info.key = new RegExp(string_utils.escapeRegExp(req.rpc_params.key_query), 'i');
} else if (req.rpc_params.key_regexp) {
Expand Down

0 comments on commit d2ba040

Please sign in to comment.