+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
angular.
module('Arvados', []).
service('ArvadosClient', ArvadosClient);
var meth = discoveryDoc.resources[controller].methods[action];
var data = $.extend({}, params, {_method: meth.httpMethod});
$.each(data, function(k, v) {
- if (typeof(v) == 'object') {
+ if (typeof(v) === 'object') {
data[k] = JSON.stringify(v);
}
});
});
}
- function uniqueNameForManifest(manifest, streamName, origName) {
+ function uniqueNameForManifest(manifest, newStreamName, origName) {
// Return an (escaped) filename starting with (unescaped)
- // origName that won't conflict with any existing names in
- // the manifest if saved under streamName. streamName must
- // be exactly as given in the manifest, e.g., "." or
- // "./foo" or "./foo/bar".
+ // origName that won't conflict with any existing names in the
+ // manifest if saved under newStreamName. newStreamName must
+ // be exactly as given in the manifest, e.g., "." or "./foo"
+ // or "./foo/bar".
//
// Example:
//
- // unique('./foo [...] 0:0:bar\040baz\n', '.', 'foo/bar baz')
+ // uniqueNameForManifest('./foo [...] 0:0:bar\\040baz.txt\n', '.',
+ // 'foo/bar baz.txt')
// =>
- // 'foo/bar\\040baz\\040(1)'
+ // 'foo/bar\\040baz\\040(1).txt'
var newName;
var nameStub = origName;
var suffixInt = null;
var ok = false;
+ var lineMatch, linesRe = /(\S+).*/gm;
+ var fileTokenMatch, fileTokensRe = / \d+:\d+:(\S+)/g;
while (!ok) {
ok = true;
// Add ' (N)' before the filename extension, if any.
newName = (!suffixInt ? nameStub :
nameStub.replace(/(\.[^.]*)?$/, ' ('+suffixInt+')$1')).
replace(/ /g, '\\040');
- $.each(manifest.split('\n'), function(_, line) {
- var i, match, foundName;
- var toks = line.split(' ');
- for (var i=1; i<toks.length && ok; i++)
- if (match = toks[i].match(/^\d+:\d+:(\S+)/))
- if (toks[0] + '/' + match[1] === streamName + '/' + newName) {
- suffixInt = (suffixInt || 0) + 1;
- ok = false;
- }
- });
+ while (ok && null !==
+ (lineMatch = linesRe.exec(manifest))) {
+ // lineMatch is [theEntireLine, streamName]
+ while (ok && null !==
+ (fileTokenMatch = fileTokensRe.exec(lineMatch[0]))) {
+ // fileTokenMatch is [theEntireToken, fileName]
+ if (lineMatch[1] + '/' + fileTokenMatch[1]
+ ===
+ newStreamName + '/' + newName) {
+ ok = false;
+ }
+ }
+ }
+ suffixInt = (suffixInt || 0) + 1;
}
return newName;
}