【问题标题】:gsutil: Can't touch a file with brackets in the namegsutil:无法触摸名称中带有括号的文件
【发布时间】:2016-08-15 06:27:08
【问题描述】:

$ gsutil du -sh gs://test123/

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

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

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

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

CommandException:没有匹配的 URL:

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

【问题讨论】:

    标签: cloud bucket gsutil


    【解决方案1】:

    由于这里没有任何答案,我将发布我所做的。我没有付出任何努力使它易于使用。 YMMV。

    1. 从 GitHub 查看 gsutil
    2. 返回提交 d153cb33bfa8e96a32b2ebdee86e03251cfb71fd,这是我工作的地方。
    3. 在阅读提交消息并确保您知道它被阻止的原因后恢复提交 46c09952d137e8704c1209bb8bdfbb2e73a2cd5d
    4. 应用此消息底部的补丁。它有效地将[] 禁用为通配符。

    我还向 gsutil 提交了 a bug 以重新引入支持。

    这是补丁:

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

    【讨论】:

      猜你喜欢
      • 2012-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-21
      • 1970-01-01
      • 1970-01-01
      • 2023-02-18
      相关资源
      最近更新 更多