From 69259465264206a0942e293ffdd29a6c49283b3e Mon Sep 17 00:00:00 2001 From: Terence Boldt Date: Mon, 26 Aug 2024 16:54:18 -0400 Subject: [PATCH] Add support for reading from cache --- main.go | 2 +- prodos/host.go | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index a2fbcde..6549cf8 100644 --- a/main.go +++ b/main.go @@ -214,7 +214,7 @@ func put(fileName string, pathName string, fileType uint8, auxType uint16, inFil fmt.Printf("Failed get fileInfo for %s - %s", fileName, err) } - err = prodos.WriteFileFromFile(file, pathName, fileType, auxType, fileInfo.ModTime(), inFileName, false) + err = prodos.WriteFileFromFile(file, pathName, fileType, auxType, fileInfo.ModTime(), inFileName, nil, false) if err != nil { fmt.Printf("Failed to write file %s", err) } diff --git a/prodos/host.go b/prodos/host.go index 2681594..7cb0876 100644 --- a/prodos/host.go +++ b/prodos/host.go @@ -10,6 +10,7 @@ import ( "encoding/binary" "errors" "fmt" + "io/fs" "os" "path/filepath" "regexp" @@ -41,6 +42,8 @@ func AddFilesFromHostDirectory( return err } + cacheDir := getCacheDir(files) + for _, file := range files { info, err := file.Info() if err != nil { @@ -48,7 +51,7 @@ func AddFilesFromHostDirectory( } if file.Name()[0] != '.' && !file.IsDir() && info.Size() > 0 && info.Size() <= 0x1000000 { - err = WriteFileFromFile(readerWriter, path, 0, 0, info.ModTime(), filepath.Join(directory, file.Name()), true) + err = WriteFileFromFile(readerWriter, path, 0, 0, info.ModTime(), filepath.Join(directory, file.Name()), cacheDir, true) if err != nil { return err } @@ -84,6 +87,7 @@ func WriteFileFromFile( auxType uint16, modifiedTime time.Time, inFileName string, + cacheDir fs.DirEntry, ignoreDuplicates bool, ) error { @@ -268,3 +272,13 @@ func isAppleSingleMagicNumber(inFile []byte) bool { } return false } + +func getCacheDir(files []fs.DirEntry) fs.DirEntry { + for _, file := range files { + if file.Name() == ".prodoscache" { + return file + } + } + + return nil +}