Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-ha committed Mar 10, 2024
1 parent 030ae75 commit cb4da23
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
25 changes: 17 additions & 8 deletions discovery/fileinformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,36 @@ package discovery
import (
"io/fs"
"os"
"path/filepath"
)

type FileInformation struct {
FullPath string
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
}
5 changes: 2 additions & 3 deletions logic/logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
10 changes: 7 additions & 3 deletions state/statemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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]
Expand Down

0 comments on commit cb4da23

Please sign in to comment.