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

Correcting panic & formatting issues with sync #2781

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
49 changes: 17 additions & 32 deletions cmd/copyEnumeratorInit.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,39 +279,24 @@ func (cca *CookedCopyCmdArgs) initEnumerator(jobPartOrder common.CopyJobPartOrde

if cca.dryrunMode && shouldSendToSte {
glcm.Dryrun(func(format common.OutputFormat) string {
if format == common.EOutputFormat.Json() {
jsonOutput, err := json.Marshal(transfer)
common.PanicIfErr(err)
return string(jsonOutput)
} else {
if cca.FromTo.From() == common.ELocation.Local() {
// formatting from local source
dryrunValue := fmt.Sprintf("DRYRUN: copy %v", common.ToShortPath(cca.Source.Value))
if runtime.GOOS == "windows" {
dryrunValue += strings.ReplaceAll(srcRelPath, "/", "\\")
} else { // linux and mac
dryrunValue += srcRelPath
}
dryrunValue += fmt.Sprintf(" to %v%v", strings.Trim(cca.Destination.Value, "/"), dstRelPath)
return dryrunValue
} else if cca.FromTo.To() == common.ELocation.Local() {
// formatting to local source
dryrunValue := fmt.Sprintf("DRYRUN: copy %v%v to %v",
strings.Trim(cca.Source.Value, "/"), srcRelPath,
common.ToShortPath(cca.Destination.Value))
if runtime.GOOS == "windows" {
dryrunValue += strings.ReplaceAll(dstRelPath, "/", "\\")
} else { // linux and mac
dryrunValue += dstRelPath
}
return dryrunValue
} else {
return fmt.Sprintf("DRYRUN: copy %v%v to %v%v",
cca.Source.Value,
srcRelPath,
cca.Destination.Value,
dstRelPath)
src := common.GenerateFullPath(cca.Source.Value, srcRelPath)
dst := common.GenerateFullPath(cca.Destination.Value, dstRelPath)

switch format {
case common.EOutputFormat.Json():
tx := DryrunTransfer{
EntityType: transfer.EntityType,
BlobType: common.FromBlobType(transfer.BlobType),
FromTo: cca.FromTo,
Source: src,
Destination: dst,
}

buf, _ := json.Marshal(tx)
return string(buf)
default:
return fmt.Sprintf("DRYRUN: copy %v to %v",
src, dst)
}
})
return nil
Expand Down
57 changes: 51 additions & 6 deletions cmd/removeEnumerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package cmd

import (
"context"
"encoding/json"
"errors"
"fmt"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azdatalake"
Expand Down Expand Up @@ -229,8 +230,22 @@ func removeBfsResources(cca *CookedCopyCmdArgs) (err error) {
func dryrunRemoveSingleDFSResource(ctx context.Context, dsc *service.Client, datalakeURLParts azdatalake.URLParts, recursive bool) error {
//deleting a filesystem
if datalakeURLParts.PathName == "" {
glcm.Dryrun(func(_ common.OutputFormat) string {
return fmt.Sprintf("DRYRUN: remove filesystem %s", datalakeURLParts.FileSystemName)
glcm.Dryrun(func(of common.OutputFormat) string {
switch of {
case of.Text():
return fmt.Sprintf("DRYRUN: remove %s", dsc.NewFileSystemClient(datalakeURLParts.FileSystemName).DFSURL())
case of.Json():
tx := DryrunTransfer{
EntityType: common.EEntityType.Folder(),
FromTo: common.EFromTo.BlobFSTrash(),
Source: dsc.NewFileSystemClient(datalakeURLParts.FileSystemName).DFSURL(),
}

buf, _ := json.Marshal(tx)
return string(buf)
default:
panic("unsupported output format " + of.String())
}
})
return nil
}
Expand All @@ -246,8 +261,22 @@ func dryrunRemoveSingleDFSResource(ctx context.Context, dsc *service.Client, dat
// then we should short-circuit and simply remove that file
resourceType := common.IffNotNil(props.ResourceType, "")
if strings.EqualFold(resourceType, "file") {
glcm.Dryrun(func(_ common.OutputFormat) string {
return fmt.Sprintf("DRYRUN: remove file %s", datalakeURLParts.PathName)
glcm.Dryrun(func(of common.OutputFormat) string {
switch of {
case of.Text():
return fmt.Sprintf("DRYRUN: remove %s", directoryClient.DFSURL())
case of.Json():
tx := DryrunTransfer{
EntityType: common.EEntityType.File(),
FromTo: common.EFromTo.BlobFSTrash(),
Source: directoryClient.DFSURL(),
}

buf, _ := json.Marshal(tx)
return string(buf)
default:
panic("unsupported output format " + of.String())
}
})
return nil
}
Expand All @@ -267,8 +296,24 @@ func dryrunRemoveSingleDFSResource(ctx context.Context, dsc *service.Client, dat
entityType = "file"
}

glcm.Dryrun(func(_ common.OutputFormat) string {
return fmt.Sprintf("DRYRUN: remove %s %s", entityType, *v.Name)
glcm.Dryrun(func(of common.OutputFormat) string {
uri := dsc.NewFileSystemClient(datalakeURLParts.FileSystemName).NewFileClient(*v.Name).DFSURL()

switch of {
case of.Text():
return fmt.Sprintf("DRYRUN: remove %s", uri)
case of.Json():
tx := DryrunTransfer{
EntityType: common.Iff(entityType == "directory", common.EEntityType.Folder(), common.EEntityType.File()),
FromTo: common.EFromTo.BlobFSTrash(),
Source: uri,
}

buf, _ := json.Marshal(tx)
return string(buf)
default:
panic("unsupported output format " + of.String())
}
})
}
}
Expand Down
12 changes: 11 additions & 1 deletion cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,17 @@ func (raw *rawSyncCmdArgs) cook() (cookedSyncCmdArgs, error) {
jobsAdmin.JobsAdmin.LogToJobLog(LocalToFileShareWarnMsg, common.LogWarning)
}
if raw.dryrun {
glcm.Dryrun(func(_ common.OutputFormat) string {
glcm.Dryrun(func(of common.OutputFormat) string {
if of == common.EOutputFormat.Json() {
var out struct {
Warn string `json:"warn"`
}

out.Warn = LocalToFileShareWarnMsg
buf, _ := json.Marshal(out)
return string(buf)
}

return fmt.Sprintf("DRYRUN: warn %s", LocalToFileShareWarnMsg)
})
}
Expand Down
51 changes: 18 additions & 33 deletions cmd/syncProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"net/url"
"os"
"path"
"runtime"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
Expand Down Expand Up @@ -75,24 +74,6 @@ type interactiveDeleteProcessor struct {
dryrunMode bool
}

func newDeleteTransfer(object StoredObject) (newDeleteTransfer common.CopyTransfer) {
return common.CopyTransfer{
Source: object.relativePath,
EntityType: object.entityType,
LastModifiedTime: object.lastModifiedTime,
SourceSize: object.size,
ContentType: object.contentType,
ContentEncoding: object.contentEncoding,
ContentDisposition: object.contentDisposition,
ContentLanguage: object.contentLanguage,
CacheControl: object.cacheControl,
Metadata: object.Metadata,
BlobType: object.blobType,
BlobVersionID: object.blobVersionID,
BlobTags: object.blobTags,
}
}

func (d *interactiveDeleteProcessor) removeImmediately(object StoredObject) (err error) {
if d.shouldPromptUser {
d.shouldDelete, d.shouldPromptUser = d.promptForConfirmation(object) // note down the user's decision
Expand All @@ -105,22 +86,24 @@ func (d *interactiveDeleteProcessor) removeImmediately(object StoredObject) (err
if d.dryrunMode {
glcm.Dryrun(func(format common.OutputFormat) string {
if format == common.EOutputFormat.Json() {
jsonOutput, err := json.Marshal(newDeleteTransfer(object))
deleteTarget := common.ELocation.Local()
if d.objectTypeToDisplay != LocalFileObjectType {
_ = deleteTarget.Parse(d.objectTypeToDisplay)
}

tx := DryrunTransfer{
Source: common.GenerateFullPath(d.objectLocationToDisplay, object.relativePath),
BlobType: common.FromBlobType(object.blobType),
EntityType: object.entityType,
FromTo: common.FromToValue(deleteTarget, common.ELocation.Unknown()),
}

jsonOutput, err := json.Marshal(tx)
common.PanicIfErr(err)
return string(jsonOutput)
} else { // remove for sync
if d.objectTypeToDisplay == "local file" { // removing from local src
dryrunValue := fmt.Sprintf("DRYRUN: remove %v", common.ToShortPath(d.objectLocationToDisplay))
if runtime.GOOS == "windows" {
dryrunValue += "\\" + strings.ReplaceAll(object.relativePath, "/", "\\")
} else { // linux and mac
dryrunValue += "/" + object.relativePath
}
return dryrunValue
}
return fmt.Sprintf("DRYRUN: remove %v/%v",
d.objectLocationToDisplay,
object.relativePath)
return fmt.Sprintf("DRYRUN: remove %v",
common.GenerateFullPath(d.objectLocationToDisplay, object.relativePath))
}
})
return nil
Expand Down Expand Up @@ -189,9 +172,11 @@ func newInteractiveDeleteProcessor(deleter objectProcessor, deleteDestination co
}
}

const LocalFileObjectType = "local file"

func newSyncLocalDeleteProcessor(cca *cookedSyncCmdArgs, fpo common.FolderPropertyOption) *interactiveDeleteProcessor {
localDeleter := localFileDeleter{rootPath: cca.destination.ValueLocal(), fpo: fpo, folderManager: common.NewFolderDeletionManager(context.Background(), fpo, azcopyScanningLogger)}
return newInteractiveDeleteProcessor(localDeleter.deleteFile, cca.deleteDestination, "local file", cca.destination, cca.incrementDeletionCount, cca.dryrunMode)
return newInteractiveDeleteProcessor(localDeleter.deleteFile, cca.deleteDestination, LocalFileObjectType, cca.destination, cca.incrementDeletionCount, cca.dryrunMode)
}

type localFileDeleter struct {
Expand Down
Loading
Loading