$ gsutil du -sh gs://test123/
CommandException: Cloud folder gs://test123/testfile[1994]/ contains a wildcard; gsutil does not currently support objects with wildcards in their name.
$ gsutil mv gs://test123/testfile[1994]/ gs://test123/testfile_1994/
CommandException: Cloud folder gs://test123/testfile[1994]/ contains a wildcard; gsutil does not currently support objects with wildcards in their name.
$ gsutil mv "gs://test123/testfile\[1994\]/" gs://test123/testfile_1994/
CommandException: No URLs matched:
I'm unable to list the directory, or rename the folder. What should I do?
Since there isn't any answers here whatsoever, I'll post what I've done. I haven't put any effort into making this easy to use. YMMV.
- Check out gsutil from GitHub
- Go back to commit
d153cb33bfa8e96a32b2ebdee86e03251cfb71fd
, which is where I was working at.
- Revert commit
46c09952d137e8704c1209bb8bdfbb2e73a2cd5d
after reading the commit message and making sure you're aware of why this was blocked.
- Apply the patch at the bottom of this message. It effectively disables
[
and ]
as wildcard characters.
I've also filed a bug against gsutil to reintroduce support.
Here's the patch:
diff --git a/gslib/storage_url.py b/gslib/storage_url.py
index 8f1df95..30308ac 100644
--- a/gslib/storage_url.py
+++ b/gslib/storage_url.py
@@ -35,7 +35,7 @@ S3_VERSION_REGEX = re.compile(r'(?P<object>.+)#(?P<version_id>.+)$')
# Matches file strings of the form 'file://dir/filename'
FILE_OBJECT_REGEX = re.compile(r'([^:]*://)(?P<filepath>.*)')
# Regex to determine if a string contains any wildcards.
-WILDCARD_REGEX = re.compile(r'[*?\[\]]')
+WILDCARD_REGEX = re.compile(r'\*')
class StorageUrl(object):
diff --git a/gslib/wildcard_iterator.py b/gslib/wildcard_iterator.py
index c3194c2..8cde4df 100644
--- a/gslib/wildcard_iterator.py
+++ b/gslib/wildcard_iterator.py
@@ -202,7 +202,8 @@ class CloudWildcardIterator(WildcardIterator):
url = StorageUrlFromString(urls_needing_expansion.pop(0))
(prefix, delimiter, prefix_wildcard, suffix_wildcard) = (
self._BuildBucketFilterStrings(url.object_name))
- prog = re.compile(fnmatch.translate(prefix_wildcard))
+ prog = re.compile(fnmatch.translate(
+ prefix_wildcard).replace("[", "\[").replace("]", "\]"))
# If we have a suffix wildcard, we only care about listing prefixes.
listing_fields = (