gsutil: Can't touch a file with brackets in the name

杀马特。学长 韩版系。学妹 提交于 2019-12-12 03:24:11

问题


$ 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?


回答1:


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.

  1. Check out gsutil from GitHub
  2. Go back to commit d153cb33bfa8e96a32b2ebdee86e03251cfb71fd, which is where I was working at.
  3. Revert commit 46c09952d137e8704c1209bb8bdfbb2e73a2cd5d after reading the commit message and making sure you're aware of why this was blocked.
  4. 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 = (


来源:https://stackoverflow.com/questions/36780004/gsutil-cant-touch-a-file-with-brackets-in-the-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!