mirror of
https://github.com/AppleCommander/AppleCommander.git
synced 2024-12-26 03:33:00 +00:00
Fixing omission in 'acx copy' command where target directory is utterly ignored. #104
This commit is contained in:
parent
745895d553
commit
1c6bc6238b
@ -23,9 +23,8 @@ import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.webcodepro.applecommander.storage.Disk;
|
||||
import com.webcodepro.applecommander.storage.DiskException;
|
||||
import com.webcodepro.applecommander.storage.FormattedDisk;
|
||||
import com.webcodepro.applecommander.storage.*;
|
||||
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;
|
||||
@ -72,19 +71,29 @@ public class CopyFileCommand extends ReadWriteDiskCommandOptions {
|
||||
if (files.isEmpty()) {
|
||||
LOG.warning(() -> String.format("No matches found for %s.", String.join(",", globs)));
|
||||
} else {
|
||||
files.forEach(this::fileHandler);
|
||||
DirectoryEntry targetDirectory = disk.getFormattedDisks()[0];
|
||||
if (targetPath != null) {
|
||||
Name name = new Name(targetPath);
|
||||
FileEntry found = name.getEntry(targetDirectory);
|
||||
if (found == null || !found.isDirectory()) {
|
||||
throw new RuntimeException("unable to find directory: " + targetPath);
|
||||
}
|
||||
targetDirectory = (DirectoryEntry) found;
|
||||
}
|
||||
for (FileTuple tuple : files) {
|
||||
fileHandler(targetDirectory, tuple);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private void fileHandler(FileTuple tuple) {
|
||||
private void fileHandler(DirectoryEntry directoryEntry, FileTuple tuple) {
|
||||
try {
|
||||
FormattedDisk formattedDisk = disk.getFormattedDisks()[0];
|
||||
if (!recursiveFlag && tuple.fileEntry.isDirectory()) {
|
||||
formattedDisk.createDirectory(tuple.fileEntry.getFilename());
|
||||
directoryEntry.createDirectory(tuple.fileEntry.getFilename());
|
||||
} else {
|
||||
FileUtils copier = new FileUtils(overwriteFlag);
|
||||
copier.copy(formattedDisk, tuple.fileEntry);
|
||||
copier.copy(directoryEntry, tuple.fileEntry);
|
||||
}
|
||||
} catch (DiskException ex) {
|
||||
LOG.severe(ex.getMessage());
|
||||
|
@ -45,8 +45,8 @@ public class Name {
|
||||
this.name = path[path.length - 1];
|
||||
}
|
||||
|
||||
public FileEntry getEntry(FormattedDisk formattedDisk) throws DiskException {
|
||||
List<FileEntry> files = formattedDisk.getFiles();
|
||||
public FileEntry getEntry(DirectoryEntry directoryEntry) throws DiskException {
|
||||
List<FileEntry> files = directoryEntry.getFiles();
|
||||
FileEntry entry = null;
|
||||
for (int i = 0; i < path.length - 1; i++) {
|
||||
String dirName = path[i];
|
||||
@ -68,11 +68,11 @@ public class Name {
|
||||
return null;
|
||||
}
|
||||
|
||||
public FileEntry createEntry(FormattedDisk formattedDisk) throws DiskException {
|
||||
public FileEntry createEntry(DirectoryEntry directoryEntry) throws DiskException {
|
||||
if (path.length == 1) {
|
||||
return formattedDisk.createFile();
|
||||
return directoryEntry.createFile();
|
||||
}
|
||||
List<FileEntry> files = formattedDisk.getFiles();
|
||||
List<FileEntry> files = directoryEntry.getFiles();
|
||||
DirectoryEntry dir = null, parentDir = null;
|
||||
for (int i = 0; i < path.length - 1; i++) {
|
||||
String dirName = path[i];
|
||||
@ -94,7 +94,7 @@ public class Name {
|
||||
parentDir = dir;
|
||||
} else {
|
||||
// Add the directory to the root of the filesystem
|
||||
dir = formattedDisk.createDirectory(dirName);
|
||||
dir = directoryEntry.createDirectory(dirName);
|
||||
parentDir = dir;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user