Fixing recursive acx copy. #130

This commit is contained in:
Rob Greene 2023-10-27 16:37:03 -05:00
parent a375e25c66
commit 5cd97c6d35
5 changed files with 39 additions and 17 deletions

View File

@ -19,16 +19,14 @@
*/
package io.github.applecommander.acx.command;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import com.webcodepro.applecommander.storage.*;
import com.webcodepro.applecommander.storage.DirectoryEntry;
import com.webcodepro.applecommander.storage.Disk;
import com.webcodepro.applecommander.storage.DiskException;
import com.webcodepro.applecommander.storage.FileEntry;
import com.webcodepro.applecommander.util.Name;
import com.webcodepro.applecommander.util.filestreamer.FileStreamer;
import com.webcodepro.applecommander.util.filestreamer.FileTuple;
import com.webcodepro.applecommander.util.filestreamer.TypeOfFile;
import io.github.applecommander.acx.base.ReadWriteDiskCommandOptions;
import io.github.applecommander.acx.converter.DiskConverter;
import io.github.applecommander.acx.fileutil.FileUtils;
@ -36,6 +34,10 @@ import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
import java.util.List;
import java.util.logging.Logger;
import java.util.stream.Collectors;
@Command(name = "copy", description = "Copy files between disks.",
aliases = { "cp" })
public class CopyFileCommand extends ReadWriteDiskCommandOptions {
@ -63,7 +65,7 @@ public class CopyFileCommand extends ReadWriteDiskCommandOptions {
List<FileTuple> files = FileStreamer.forDisk(sourceDisk)
.ignoreErrors(true)
.includeTypeOfFile(TypeOfFile.BOTH)
.recursive(recursiveFlag)
.recursive(false) // we handle recursion in the FileUtils
.matchGlobs(globs)
.stream()
.collect(Collectors.toList());

View File

@ -19,17 +19,16 @@
*/
package io.github.applecommander.acx.fileutil;
import java.util.Optional;
import java.util.logging.Logger;
import com.webcodepro.applecommander.storage.DirectoryEntry;
import com.webcodepro.applecommander.storage.DiskException;
import com.webcodepro.applecommander.storage.FileEntry;
import com.webcodepro.applecommander.util.readerwriter.FileEntryReader;
import com.webcodepro.applecommander.util.readerwriter.FileEntryWriter;
import io.github.applecommander.acx.command.CopyFileCommand;
import java.util.Optional;
import java.util.logging.Logger;
public class FileUtils {
private static Logger LOG = Logger.getLogger(CopyFileCommand.class.getName());
@ -40,7 +39,7 @@ public class FileUtils {
}
public void copy(DirectoryEntry directory, FileEntry file) throws DiskException {
LOG.fine(() -> String.format("Copying '%s'", file.getFilename()));
LOG.fine(() -> String.format("Copying '%s' into directory '%s'", file.getFilename(), directory.getDirname()));
if (file.isDeleted()) {
// Skip deleted files
}
@ -112,13 +111,15 @@ public class FileUtils {
source.getBinaryAddress().ifPresent(target::setBinaryAddress);
source.getBinaryLength().ifPresent(target::setBinaryLength);
source.getAuxiliaryType().ifPresent(target::setAuxiliaryType);
source.getCreationDate().ifPresent(target::setCreationDate);
source.getLastModificationDate().ifPresent(target::setLastModificationDate);
source.getCreationDate().ifPresent(target::setCreationDate);
if (source.getFileData().isPresent() && source.getResourceData().isPresent()) {
target.setFileData(source.getFileData().get(), source.getResourceData().get());
} else {
source.getFileData().ifPresent(target::setFileData);
}
// Modification date needs to be done last since writing file data/attributes are likely to change it
source.getLastModificationDate().ifPresent(target::setLastModificationDate);
}
}

View File

@ -33,6 +33,11 @@ import java.util.List;
* @author Lisias Toledo
*/
public interface DirectoryEntry {
/**
* Return a name for this directory.
*/
public String getDirname();
/**
* Retrieve the list of files in this directory.
* Note that if this is not a directory, the return

View File

@ -140,7 +140,14 @@ public abstract class FormattedDisk extends Disk implements DirectoryEntry {
* but "DISK VOLUME #xxx" (DOS 3.3) or "/MY.DISK" (ProDOS).
*/
public abstract String getDiskName();
/**
* Return a name for this directory.
*/
public String getDirname(){
return getDiskName();
}
/**
* Set the name of the disk to volumeName.
*/

View File

@ -19,13 +19,13 @@
*/
package com.webcodepro.applecommander.storage.os.prodos;
import java.util.List;
import com.webcodepro.applecommander.storage.DirectoryEntry;
import com.webcodepro.applecommander.storage.DiskException;
import com.webcodepro.applecommander.storage.DiskFullException;
import com.webcodepro.applecommander.storage.FileEntry;
import java.util.List;
/**
* Implement directory functionality.
* <p>
@ -55,6 +55,13 @@ public class ProdosDirectoryEntry extends ProdosFileEntry implements DirectoryEn
return this.subdirectoryHeader;
}
/**
* Return a name for this directory.
*/
public String getDirname(){
return getFilename();
}
/**
* Retrieve the list of files in this directory.
* Note that if this is not a directory, the return