Fixing a wrongly placed DiskException handler on the command line tool.

This commit is contained in:
Lisias 2018-01-08 08:20:18 -02:00
parent ae66b88e0a
commit f3316262c8
2 changed files with 23 additions and 26 deletions

View File

@ -26,6 +26,7 @@ import java.io.PrintStream;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import com.webcodepro.applecommander.storage.Disk;
import com.webcodepro.applecommander.storage.DiskException;
import com.webcodepro.applecommander.storage.FormattedDisk;
public class AntTask extends Task
@ -107,7 +108,7 @@ public class AntTask extends Task
{
com.webcodepro.applecommander.ui.ac.deleteFile(_imageName, _fileName);
}
catch (IOException io)
catch (IOException|DiskException io)
{
if (_failonerror)
throw new BuildException(io);
@ -138,7 +139,7 @@ public class AntTask extends Task
else // Assume unlock
com.webcodepro.applecommander.ui.ac.setFileLocked(_imageName, _fileName, false);
}
catch (IOException io)
catch (IOException|DiskException io)
{
if (_failonerror)
throw new BuildException(io);

View File

@ -264,7 +264,7 @@ public class ac {
* Delete the file named fileName from the disk named imageName.
*/
static void deleteFile(String imageName, String fileName)
throws IOException {
throws IOException, DiskException {
Disk disk = new Disk(imageName);
Name name = new Name(fileName);
if (!disk.isSDK() && !disk.isDC42()) {
@ -290,7 +290,7 @@ public class ac {
* filtered according to its type and sent to <stdout>.
*/
static void getFile(String imageName, String fileName, boolean filter, PrintStream out)
throws IOException {
throws IOException, DiskException {
Disk disk = new Disk(imageName);
Name name = new Name(fileName);
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
@ -479,7 +479,7 @@ public class ac {
* Set the lockState of the file named fileName on the disk named imageName.
* Proposed by David Schmidt.
*/
public static void setFileLocked(String imageName, String name, boolean lockState) throws IOException {
public static void setFileLocked(String imageName, String name, boolean lockState) throws IOException, DiskException {
setFileLocked(imageName, new Name(name), lockState);
}
@ -488,7 +488,7 @@ public class ac {
* Proposed by David Schmidt.
*/
static void setFileLocked(String imageName, Name name,
boolean lockState) throws IOException {
boolean lockState) throws IOException, DiskException {
Disk disk = new Disk(imageName);
if (!disk.isSDK() && !disk.isDC42()) {
FormattedDisk[] formattedDisks = disk.getFormattedDisks();
@ -620,29 +620,25 @@ public class ac {
this.name = path[path.length - 1];
}
public FileEntry getEntry(FormattedDisk formattedDisk) {
try {
List files = formattedDisk.getFiles();
FileEntry entry = null;
for (int i = 0; i < path.length - 1; i++) {
String dirName = path[i];
for (int j = 0; j < files.size(); j++) {
entry = (FileEntry) files.get(j);
String entryName = entry.getFilename();
if (entry.isDirectory() && dirName.equalsIgnoreCase(entryName)) {
files = ((DirectoryEntry) entry).getFiles();
}
}
}
for (int i = 0; i < files.size(); i++) {
entry = (FileEntry) files.get(i);
public FileEntry getEntry(FormattedDisk formattedDisk) throws DiskException {
List files = formattedDisk.getFiles();
FileEntry entry = null;
for (int i = 0; i < path.length - 1; i++) {
String dirName = path[i];
for (int j = 0; j < files.size(); j++) {
entry = (FileEntry) files.get(j);
String entryName = entry.getFilename();
if (!entry.isDeleted() && name.equalsIgnoreCase(entryName)) {
return entry;
if (entry.isDirectory() && dirName.equalsIgnoreCase(entryName)) {
files = ((DirectoryEntry) entry).getFiles();
}
}
} catch (DiskException e) {
// FIXME How to warn user about the problem?
}
for (int i = 0; i < files.size(); i++) {
entry = (FileEntry) files.get(i);
String entryName = entry.getFilename();
if (!entry.isDeleted() && name.equalsIgnoreCase(entryName)) {
return entry;
}
}
return null;
}