Skip to content

Commit 2b8c7c4

Browse files
fix panic with folder creation tracker validation (#3403)
* already existing folders should not be recreated * fix * unit test fct fix
1 parent a6eca3b commit 2b8c7c4

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
lines changed

e2etest/zt_newe2e_file_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package e2etest
33
import (
44
"context"
55
"fmt"
6-
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
7-
"github.com/Azure/azure-storage-azcopy/v10/common"
86
"math"
97
"os"
108
"strconv"
9+
10+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
11+
"github.com/Azure/azure-storage-azcopy/v10/common"
1112
)
1213

1314
func init() {

ste/folderCreationTracker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ func (f *jpptFolderTracker) CreateFolder(folder string, doCreation func() error)
137137
ts == common.ETransferStatus.FolderExisted() ||
138138
ts == common.ETransferStatus.Cancelled() ||
139139
ts == common.ETransferStatus.Success() ||
140-
ts == common.ETransferStatus.Failed() {
140+
ts == common.ETransferStatus.Failed() ||
141+
ts == common.ETransferStatus.SkippedEntityAlreadyExists() {
142+
141143
return nil // do not re-create an existing folder
142144
}
143145
} else {

ste/folderCreationTracker_test.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestFolderCreationTracker_directoryExists(t *testing.T) {
159159
}) // "create" our folder
160160
err := fct.CreateFolder(folderExists, func() error {
161161
return common.FolderCreationErrorAlreadyExists{}
162-
}) // fail creation on not existing
162+
}) // fail creation on not existing
163163
a.NoError(err, "already exists should be caught") // ensure we caught that error
164164
expectedFailureErr := errors.New("this creation should fail")
165165
err = fct.CreateFolder(folderShouldCreate, func() error {
@@ -194,3 +194,45 @@ func TestFolderCreationTracker_directoryExists(t *testing.T) {
194194

195195
a.NoError(err)
196196
}
197+
198+
// Verifies that a subsequent call to createFolder does not panic when the status is
199+
// SkippedEntityAlreadyExists
200+
func TestFolderCreationTracker_skippedEntityExits(t *testing.T) {
201+
a := assert.New(t)
202+
203+
folderExists := "folderExists"
204+
existsIdx := JpptFolderIndex{0, 0}
205+
206+
plan := &mockedJobPlan{
207+
transfers: map[JpptFolderIndex]*JobPartPlanTransfer{
208+
existsIdx: {atomicTransferStatus: common.ETransferStatus.NotStarted()},
209+
},
210+
}
211+
212+
fct := &jpptFolderTracker{
213+
fetchTransfer: plan.getFetchTransfer(t),
214+
mu: &sync.Mutex{},
215+
contents: make(map[string]*JpptFolderTrackerState),
216+
}
217+
218+
fct.RegisterPropertiesTransfer(folderExists, existsIdx.PartNum, existsIdx.TransferIndex)
219+
err := fct.CreateFolder(folderExists, func() error {
220+
return common.FolderCreationErrorAlreadyExists{}
221+
})
222+
a.NoError(err, "already exists should be caught")
223+
a.Equal(common.ETransferStatus.FolderExisted(), plan.transfers[existsIdx].TransferStatus())
224+
225+
// Simulate folder transfer setting properties this happens in any_toremotefolder
226+
plan.transfers[existsIdx].SetTransferStatus(common.ETransferStatus.SkippedEntityAlreadyExists(), false)
227+
228+
folderCreated := false
229+
a.NotPanics(func() { // Subsequent call to createFolder should not panic
230+
err = fct.CreateFolder(folderExists, func() error {
231+
folderCreated = true
232+
return nil
233+
})
234+
})
235+
a.NoError(err)
236+
a.False(folderCreated, "createFolder should return early without calling doCreation")
237+
238+
}

0 commit comments

Comments
 (0)