Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent panic on remove with include before param on file share accounts #2270

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/removeEnumerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func newRemoveEnumerator(cca *CookedCopyCmdArgs) (enumerator *CopyEnumerator, er
ctx := context.WithValue(context.TODO(), ste.ServiceAPIVersionOverride, ste.DefaultServiceApiVersion)

// Include-path is handled by ListOfFilesChannel.
sourceTraverser, err = InitResourceTraverser(cca.Source, cca.FromTo.From(), &ctx, &cca.credentialInfo, common.ESymlinkHandlingType.Skip(), cca.ListOfFilesChannel, cca.Recursive, false, cca.IncludeDirectoryStubs, cca.permanentDeleteOption, func(common.EntityType) {}, cca.ListOfVersionIDs, false, common.ESyncHashType.None(), common.EPreservePermissionsOption.None(), azcopyLogVerbosity.ToPipelineLogLevel(), cca.CpkOptions, nil, cca.StripTopDir, cca.trailingDot, nil, nil)
sourceTraverser, err = InitResourceTraverser(cca.Source, cca.FromTo.From(), &ctx, &cca.credentialInfo, common.ESymlinkHandlingType.Skip(), cca.ListOfFilesChannel, cca.Recursive, true, cca.IncludeDirectoryStubs, cca.permanentDeleteOption, func(common.EntityType) {}, cca.ListOfVersionIDs, false, common.ESyncHashType.None(), common.EPreservePermissionsOption.None(), azcopyLogVerbosity.ToPipelineLogLevel(), cca.CpkOptions, nil, cca.StripTopDir, cca.trailingDot, nil, nil)

// report failure to create traverser
if err != nil {
Expand Down
68 changes: 68 additions & 0 deletions e2etest/zt_remove_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright © Microsoft <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package e2etest

import (
"github.com/Azure/azure-storage-file-go/azfile"
"testing"
"time"
)

func TestRemove_IncludeAfter(t *testing.T) {
recreateFiles := []interface{}{
folder(""),
f("filea"),
}

skippedFiles := []interface{}{
folder("fold1"),
f("fold1/fileb"),
}
RunScenarios(t, eOperation.Remove(), eTestFromTo.AllRemove(), eValidate.Auto(), anonymousAuthOnly, anonymousAuthOnly, params{
recursive: true,
}, &hooks{
beforeRunJob: func(h hookHelper) {
// Pause for a includeAfter time
time.Sleep(5 * time.Second)
h.GetModifiableParameters().includeAfter = time.Now().Format(azfile.ISO8601)
// Pause then re-write all the files, so that their LastWriteTime is different from their creation time
// So that when validating, our validation can be sure that the right datetime has ended up in the right
// field
time.Sleep(5 * time.Second)
h.CreateFiles(testFiles{
defaultSize: "1K",
shouldTransfer: recreateFiles,
}, true, true, false)

// And pause again, so that that the write times at the destination wont' just _automatically_ match the source times
// (due to there being < 1 sec delay between creation and completion of copy). With this delay, we know they only match
// if AzCopy really did preserve them
time.Sleep(10 * time.Second) // we are assuming here, that the clock skew between source and dest is less than 10 secs
},
}, testFiles{
defaultSize: "1K",
// no need to set specific dates on these. Instead, we just mess with the write times in
// beforeRunJob
// TODO: is that what we really want, or do we want to set write times here?
shouldTransfer: recreateFiles,
shouldIgnore: skippedFiles,
}, EAccountType.Standard(), EAccountType.Standard(), "")
}