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

Minimise mumber of calls to folder create #2511

Merged
merged 13 commits into from
Jan 20, 2024
5 changes: 5 additions & 0 deletions ste/folderCreationTracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func (f *jpptFolderTracker) CreateFolder(folder string, doCreation func() error)
return nil // Never persist to dev-null
}

if idx, ok := f.contents[folder]; ok &&
nakulkar-msft marked this conversation as resolved.
Show resolved Hide resolved
f.plan.Transfer(idx).TransferStatus() == (common.ETransferStatus.FolderCreated()) {
return nil
}

err := doCreation()
if err != nil {
return err
Expand Down
51 changes: 20 additions & 31 deletions ste/sender-azureFile.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,39 +531,28 @@ func (d AzureFileParentDirCreator) CreateParentDirToRoot(ctx context.Context, fi
}

func (d AzureFileParentDirCreator) CreateDirToRoot(ctx context.Context, shareClient *share.Client, directoryClient *directory.Client, t FolderCreationTracker) error {
gapra-msft marked this conversation as resolved.
Show resolved Hide resolved
fileURLParts, err := file.ParseURL(directoryClient.URL())
if err != nil {
return err
}
_, err = directoryClient.GetProperties(ctx, nil)
if err != nil {
var respErr *azcore.ResponseError
if errors.As(err, &respErr) && (respErr.StatusCode == http.StatusNotFound || respErr.StatusCode == http.StatusForbidden) {
// Either the parent directory does not exist, or we may not have read permissions.
// Try to create the parent directories. Split directories as segments.
segments := d.splitWithoutToken(fileURLParts.DirectoryOrFilePath, '/')
currentDirectoryClient := shareClient.NewRootDirectoryClient() // Share directory should already exist, doesn't support creating share
// Try to create the directories
for i := 0; i < len(segments); i++ {
currentDirectoryClient = currentDirectoryClient.NewSubdirectoryClient(segments[i])
rawURL := currentDirectoryClient.URL()
recorderURL, err := url.Parse(rawURL)
if err != nil {
return err
}
recorderURL.RawQuery = ""
err = t.CreateFolder(recorderURL.String(), func() error {
_, err := currentDirectoryClient.Create(ctx, nil)
return err
})
if verifiedErr := d.verifyAndHandleCreateErrors(err); verifiedErr != nil {
return verifiedErr
}
}
} else {
// ignoring error below because we're getting URL from a valid client.
fileURLParts, _ := file.ParseURL(directoryClient.URL())

// Try to create the parent directories. Split directories as segments.
segments := d.splitWithoutToken(fileURLParts.DirectoryOrFilePath, '/')
currentDirectoryClient := shareClient.NewRootDirectoryClient() // Share directory should already exist, doesn't support creating share
// Try to create the directories
for i := 0; i < len(segments); i++ {
currentDirectoryClient = currentDirectoryClient.NewSubdirectoryClient(segments[i])
rawURL := currentDirectoryClient.URL()
recorderURL, err := url.Parse(rawURL)
if err != nil {
return err
}
recorderURL.RawQuery = ""
err = t.CreateFolder(recorderURL.String(), func() error {
_, err := currentDirectoryClient.Create(ctx, nil)
return err
})
if verifiedErr := d.verifyAndHandleCreateErrors(err); verifiedErr != nil {
return verifiedErr
}
}
// Directly return if parent directory exists.
return nil
}