Skip to content

Commit 04ff6e2

Browse files
committed
add tests for cleanup on target side
1 parent 17cd653 commit 04ff6e2

File tree

3 files changed

+75
-8
lines changed

3 files changed

+75
-8
lines changed

pkg/actors/cleaner.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,13 @@ func (c *Cleaner) Run() {
8080

8181
//perform cleanup if it is safe to do so
8282
for job, transferred := range isFileTransferred {
83-
if isJobFailed[job] || c.Context.Err() == nil {
84-
continue
83+
if c.Context.Err() != nil {
84+
//interrupt received
85+
return
86+
}
87+
if !isJobFailed[job] {
88+
c.performCleanup(job, transferred)
8589
}
86-
c.performCleanup(job, transferred)
8790
}
8891
}
8992

pkg/objects/swift.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,7 @@ func (s *SwiftLocation) DiscoverExistingFiles(matcher Matcher) error {
265265
iter.Prefix = prefix
266266
s.FileExists = make(map[string]bool)
267267
err := iter.Foreach(func(object *schwift.Object) error {
268-
path := object.Name()
269-
pathForMatching := strings.TrimPrefix(path, prefix)
270-
if matcher.CheckRecursive(pathForMatching) == "" {
271-
s.FileExists[path] = true
272-
}
268+
s.FileExists[object.Name()] = true
273269
return nil
274270
})
275271
if err != nil {

tests.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ fi
8989
################################################################################
9090
# functions for tests
9191

92+
upload_target_file_from_stdin() {
93+
# same trickery as in `upload_file_from_stdin` (see comments over there), but
94+
# for a target container
95+
sed 's/^ //' > "${TEST_FILENAME}"
96+
local CONTAINER_NAME="${CONTAINER_BASE}-$1"
97+
local OBJECT_NAME="$2"
98+
shift 2
99+
swift upload "${CONTAINER_NAME}" "${TEST_FILENAME}" --object-name "${OBJECT_NAME}" "$@"
100+
}
101+
92102
mirror() {
93103
# config file comes from stdin
94104
./build/swift-http-import /dev/fd/0
@@ -494,6 +504,64 @@ fi
494504

495505
fi # end of: if [ "$1" = http ]
496506

507+
################################################################################
508+
step 'Test 10: Cleanup on target side'
509+
510+
upload_target_file_from_stdin test10 ignored.txt <<-EOF
511+
This file does not get cleaned up because it's not below object_prefix.
512+
EOF
513+
upload_target_file_from_stdin test10 target/cleanup-please.txt <<-EOF
514+
This file gets cleaned up because it's below object_prefix.
515+
EOF
516+
# This file will get cleaned up even though it exists on the source side
517+
# because it's excluded from transfer by a filter.
518+
upload_target_file_from_stdin test10 target/just/some/files/2.txt <<-EOF
519+
Hello Second World.
520+
EOF
521+
sleep 10 # wait for container listing to get updated
522+
523+
mirror <<-EOF
524+
swift: { $AUTH_PARAMS }
525+
jobs:
526+
- from: ${SOURCE_SPEC}
527+
to:
528+
container: ${CONTAINER_BASE}-test10
529+
object_prefix: target/
530+
only: '/$|1\\.txt$'
531+
EOF
532+
533+
# This first pass does not have cleanup enabled (to compare against the second
534+
# pass down below), so we're still seeing the files that need to be cleaned up.
535+
expect test10 <<-EOF
536+
>> ignored.txt
537+
This file does not get cleaned up because it's not below object_prefix.
538+
>> target/cleanup-please.txt
539+
This file gets cleaned up because it's below object_prefix.
540+
>> target/just/some/files/1.txt
541+
Hello World.
542+
>> target/just/some/files/2.txt
543+
Hello Second World.
544+
EOF
545+
546+
mirror <<-EOF
547+
swift: { $AUTH_PARAMS }
548+
jobs:
549+
- from: ${SOURCE_SPEC}
550+
to:
551+
container: ${CONTAINER_BASE}-test10
552+
object_prefix: target/
553+
only: '/$|1\\.txt$'
554+
cleanup:
555+
strategy: delete
556+
EOF
557+
558+
expect test10 <<-EOF
559+
>> ignored.txt
560+
This file does not get cleaned up because it's not below object_prefix.
561+
>> target/just/some/files/1.txt
562+
Hello World.
563+
EOF
564+
497565
################################################################################
498566
# cleanup before exiting
499567

0 commit comments

Comments
 (0)