corgrath
corgrath

Reputation: 12295

How come file is not excluded with gsutil rsync -x by the Google Cloud Builder?

I am currently running the gsutil rsync cloud build command:

gcr.io/cloud-builders/gsutil
-m rsync -r -c -d -x "\.gitignore" . gs://mybucket/ 

I am using the -x "\.gitignore" argument here to try and not copy over the .gitignore file, as mentioned here:

https://cloud.google.com/storage/docs/gsutil/commands/rsync

However, when looking in the bucket and the logs, it still says:

2021-04-23T13:29:37.870382893Z Step #1: Copying file://./.gitignore [Content-Type=application/octet-stream]...

So rsync is still copying over the file despite the -x "\.gitignore" argument.

According to the docs -x is a Python regexp, so //./.gitignore should be captured by \.gitignore

enter image description here

Does anyone know why this isn't working and why the file is still being copied?

Upvotes: 2

Views: 159

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627082

See the rsync.py source code:

if cls.exclude_pattern.match(str_to_check):

In Python, re.match only returns a match if it occurs at the start of string.

So, in order to find a match anywhere using the -x parameter, you need to prepend the pattern you need to find with .* or with (?s).*:

gcr.io/cloud-builders/gsutil
-m rsync -r -c -d -x ".*\.gitignore" . gs://mybucket/ 

Note that to make sure .gitignore appears at the end of string, you need to append $, -x ".*\.gitignore$".

Upvotes: 2

Related Questions