mirror of
https://github.com/tjboldt/ProDOS-Utilities.git
synced 2024-12-27 05:29:49 +00:00
Ignore duplicate files when recursive
This commit is contained in:
parent
286964d3ee
commit
36c24e60ca
2
main.go
2
main.go
@ -201,7 +201,7 @@ func put(fileName string, pathName string, fileType int, auxType int, inFileName
|
||||
defer file.Close()
|
||||
fileInfo, err := os.Stat(fileName)
|
||||
|
||||
err = prodos.WriteFileFromFile(file, pathName, fileType, auxType, fileInfo.ModTime(), inFileName)
|
||||
err = prodos.WriteFileFromFile(file, pathName, fileType, auxType, fileInfo.ModTime(), inFileName, false)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to write file %s", err)
|
||||
}
|
||||
|
@ -248,6 +248,7 @@ func getFreeFileEntryInDirectory(readerWriter ReaderWriterAt, directory string)
|
||||
fileEntry := parseFileEntry(buffer[entryOffset:entryOffset+0x28], blockNumber, entryOffset)
|
||||
|
||||
if fileEntry.StorageType == StorageDeleted {
|
||||
fileEntry = FileEntry{}
|
||||
fileEntry.DirectoryBlock = blockNumber
|
||||
fileEntry.DirectoryOffset = entryOffset
|
||||
fileEntry.HeaderPointer = directoryHeader.StartingBlock
|
||||
|
@ -52,7 +52,7 @@ func WriteFile(readerWriter ReaderWriterAt, path string, fileType int, auxType i
|
||||
|
||||
existingFileEntry, _ := GetFileEntry(readerWriter, path)
|
||||
if existingFileEntry.StorageType != StorageDeleted {
|
||||
DeleteFile(readerWriter, path)
|
||||
return errors.New(("file already exists"))
|
||||
}
|
||||
|
||||
// get list of blocks to write file to
|
||||
@ -126,6 +126,10 @@ func incrementFileCount(readerWriter ReaderWriterAt, fileEntry FileEntry) error
|
||||
// DeleteFile deletes a file from a ProDOS volume
|
||||
func DeleteFile(readerWriter ReaderWriterAt, path string) error {
|
||||
fileEntry, err := GetFileEntry(readerWriter, path)
|
||||
// DumpFileEntry(fileEntry)
|
||||
// oldDirectoryBlock, _ := ReadBlock(readerWriter, fileEntry.DirectoryBlock)
|
||||
// DumpBlock(oldDirectoryBlock)
|
||||
|
||||
if err != nil {
|
||||
return errors.New("file not found")
|
||||
}
|
||||
@ -169,6 +173,12 @@ func DeleteFile(readerWriter ReaderWriterAt, path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FileExists return true if the file exists
|
||||
func FileExists(reader io.ReaderAt, path string) (bool, error) {
|
||||
fileEntry, _ := GetFileEntry(reader, path)
|
||||
return fileEntry.StorageType != StorageDeleted, nil
|
||||
}
|
||||
|
||||
// GetDirectoryAndFileNameFromPath gets the directory and filename from a path
|
||||
func GetDirectoryAndFileNameFromPath(path string) (string, string) {
|
||||
path = strings.ToUpper(path)
|
||||
|
@ -22,7 +22,8 @@ func AddFilesFromHostDirectory(
|
||||
readerWriter ReaderWriterAt,
|
||||
directory string,
|
||||
path string,
|
||||
recursive bool) error {
|
||||
recursive bool,
|
||||
) error {
|
||||
|
||||
path, err := makeFullPath(path, readerWriter)
|
||||
|
||||
@ -42,7 +43,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()))
|
||||
err = WriteFileFromFile(readerWriter, path, 0, 0, info.ModTime(), filepath.Join(directory, file.Name()), true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -56,8 +57,14 @@ func AddFilesFromHostDirectory(
|
||||
newFullPath := strings.ToUpper(path + newPath)
|
||||
|
||||
newHostDirectory := filepath.Join(directory, file.Name())
|
||||
CreateDirectory(readerWriter, newFullPath)
|
||||
AddFilesFromHostDirectory(readerWriter, newHostDirectory, newFullPath+"/", recursive)
|
||||
err = CreateDirectory(readerWriter, newFullPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = AddFilesFromHostDirectory(readerWriter, newHostDirectory, newFullPath+"/", recursive)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,7 +78,9 @@ func WriteFileFromFile(
|
||||
fileType int,
|
||||
auxType int,
|
||||
modifiedTime time.Time,
|
||||
inFileName string) error {
|
||||
inFileName string,
|
||||
ignoreDuplicates bool,
|
||||
) error {
|
||||
|
||||
inFile, err := os.ReadFile(inFileName)
|
||||
if err != nil {
|
||||
@ -117,7 +126,17 @@ func WriteFileFromFile(
|
||||
pathName = strings.Join(paths, "")
|
||||
}
|
||||
|
||||
fmt.Printf("Source: %s Destination: %s\n", inFileName, pathName)
|
||||
// skip if file already exists and ignoring duplicates
|
||||
if ignoreDuplicates {
|
||||
exists, err := FileExists(readerWriter, pathName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if exists {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return WriteFile(readerWriter, pathName, fileType, auxType, time.Now(), modifiedTime, inFile)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user