本文介绍了gsutil:无法触摸名称中带有方括号的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CommandException:云文件夹gs:// test123 / testfile [1994] /包含通配符; gsutil当前不支持名称中带有通配符的对象。

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 /

$ gsutil mv gs://test123/testfile[1994]/ gs://test123/testfile_1994/

CommandException:云文件夹gs:// test123 / testfile [1994] /包含通配符; gsutil当前不支持名称中带有通配符的对象。

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 /

$ gsutil mv "gs://test123/testfile\[1994\]/" gs://test123/testfile_1994/

CommandException:没有匹配的URL:

CommandException: No URLs matched:

我无法列出目录,或重命名文件夹。我应该怎么办?

I'm unable to list the directory, or rename the folder. What should I do?

推荐答案

由于这里没有任何答案,因此我将发布完成的工作。我并没有努力使它易于使用。 YMMV。

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. 查看

  2. 回去提交 d153cb33bfa8e96a32b2ebdee86e03251cfb71fd ,这就是我正在工作的地方。

  3. 还原提交阅读提交消息并确保您知道阻止该消息的原因。

  4. 在此消息底部应用补丁。它有效地禁用了 [] 作为通配符。

  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.

我还针对gsutil提交了重新引入支持。

I've also filed a bug against gsutil to reintroduce support.

以下是补丁:

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 = (

这篇关于gsutil:无法触摸名称中带有方括号的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 01:10