diff --git a/discovery/fileinformation.go b/discovery/fileinformation.go index 87c4584..5f38534 100644 --- a/discovery/fileinformation.go +++ b/discovery/fileinformation.go @@ -3,6 +3,7 @@ package discovery import ( "io/fs" "os" + "path/filepath" ) type FileInformation struct { @@ -10,20 +11,28 @@ type FileInformation struct { Info fs.FileInfo } -func MakeFileInformation(fullPath string) (FileInformation, error) { - stat, statErr := os.Stat(fullPath) +func MakeFileInformation(path string) (FileInformation, error) { + absPath, err := filepath.Abs(path) + if err != nil { + return FileInformation{FullPath: path, Info: nil}, err + } + stat, statErr := os.Stat(absPath) if statErr != nil { - return FileInformation{FullPath: fullPath, Info: nil}, statErr + return FileInformation{FullPath: absPath, Info: nil}, statErr } - return FileInformation{FullPath: fullPath, Info: stat}, nil + return FileInformation{FullPath: absPath, Info: stat}, nil } -func MakeFileInformationWithSymbolicLinks(fullPath string) (FileInformation, error) { - stat, statErr := os.Lstat(fullPath) +func MakeFileInformationWithSymbolicLinks(path string) (FileInformation, error) { + absPath, err := filepath.Abs(path) + if err != nil { + return FileInformation{FullPath: path, Info: nil}, err + } + stat, statErr := os.Lstat(absPath) if statErr != nil { - return FileInformation{FullPath: fullPath, Info: nil}, statErr + return FileInformation{FullPath: absPath, Info: nil}, statErr } - return FileInformation{FullPath: fullPath, Info: stat}, nil + return FileInformation{FullPath: absPath, Info: stat}, nil } diff --git a/logic/logic.go b/logic/logic.go index 4794068..4089a85 100644 --- a/logic/logic.go +++ b/logic/logic.go @@ -16,9 +16,8 @@ import ( const BLOCKSIZE = 1024 * 1024 // 1MB type JcpProgress struct { - JcpError error - Progress copier.CopierProgress - OpaqueState any + JcpError error + Progress copier.CopierProgress } type Jcp struct { diff --git a/state/state.go b/state/state.go index c5c0fca..54618b1 100644 --- a/state/state.go +++ b/state/state.go @@ -29,5 +29,5 @@ type JcpCopyState struct { func MakeNewCopyState(progress logic.JcpProgress) JcpCopyState { percent := float64(progress.Progress.BytesTransferred) / float64(progress.Progress.Size) - return JcpCopyState{OpaqueState: progress.OpaqueState, CopierType: BlockCopier, LastUpdate: time.Now(), Percent: percent} + return JcpCopyState{OpaqueState: progress.Progress.OpaqueState, CopierType: BlockCopier, LastUpdate: time.Now(), Percent: percent} } diff --git a/state/statemanager.go b/state/statemanager.go index 9ea9a32..1a8d7c2 100644 --- a/state/statemanager.go +++ b/state/statemanager.go @@ -35,7 +35,7 @@ func InitializeState() (*JcpState, error) { func loadState(fileName string) *JcpState { data, err := os.ReadFile(fileName) - loadedState := &JcpState{} + loadedState := &JcpState{CopyStates: make(map[CopySourceKey]map[CopyDestinationKey]JcpCopyState)} if err == nil { json.Unmarshal(data, loadedState) } @@ -65,10 +65,10 @@ func (copierState *JcpState) Update(progress logic.JcpProgress) { newState := MakeNewCopyState(progress) if copierState.CopyStates[progress.Progress.Source] == nil { - copierState.CopyStates[progress.Progress.Dest] = map[CopyDestinationKey]JcpCopyState{} + copierState.CopyStates[progress.Progress.Source] = map[CopyDestinationKey]JcpCopyState{} } - copierState.CopyStates[progress.Progress.Source][progress.Progress.Source] = newState + copierState.CopyStates[progress.Progress.Source][progress.Progress.Dest] = newState } func (copierState *JcpState) Clean() { @@ -78,6 +78,10 @@ func (copierState *JcpState) Clean() { newStates := make(map[CopySourceKey]map[CopyDestinationKey]JcpCopyState) for src := range copierState.CopyStates { + if newStates[src] == nil { + newStates[src] = make(map[CopyDestinationKey]JcpCopyState) + } + for dest := range copierState.CopyStates[src] { if copierState.CopyStates[src][dest].ShouldKeep() { newStates[src][dest] = copierState.CopyStates[src][dest]