Skip to content

Commit

Permalink
fix: trace exception when deleting physical files (#168)
Browse files Browse the repository at this point in the history
Signed-off-by: Jesse Gorzinski <17914061+ThePrez@users.noreply.github.com>
  • Loading branch information
ThePrez authored Mar 29, 2024
1 parent 7af50c6 commit 0d7f709
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/main/java/com/ibm/as400/access/IFSFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,36 @@ Returns false if the file system object did not exist prior to the delete() or i
public boolean delete()
throws IOException
{
// If it looks like it's in QSYS, then the stream file operation to the host server will likely not work. For
// files and members, though, we can handle specially here.
if(isInQsys()) {
AS400File tmpPF = null;
ObjectDescription objectDescription = new ObjectDescription(system_, path_.replaceAll("//+", "/"));
try {
String type = objectDescription.getType();
switch (type) {
case "FILE": //note: includes *SAVF objects
tmpPF = new SequentialFile(system_, objectDescription.getPath());
tmpPF.delete();
return true;
case "MBR":
tmpPF = new SequentialFile(system_, objectDescription.getPath());
tmpPF.deleteMember();
return true;
}
} catch (AS400SecurityException | InterruptedException | IOException | ErrorCompletingRequestException e) {
Trace.log(
Trace.WARNING, "Unable to delete QSYS file using classic techniques. Will try host server stream file operations."+path_, e);
} finally {
if(null != tmpPF) {
try {
tmpPF.close();
} catch (AS400Exception | AS400SecurityException | InterruptedException | IOException e) {
Trace.log(Trace.ERROR, "Unexpected error closing file "+path_, e);
}
}
}
}
int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
try
{
Expand Down Expand Up @@ -1776,7 +1806,22 @@ public String getSubtype()
}
return subType_;
}
private boolean isInFileSystem(String _fs) {
String lowercasePath = path_.toLowerCase().replaceAll("//+","/");
return lowercasePath.equals("/"+_fs.toLowerCase()) || lowercasePath.startsWith("/"+_fs.toLowerCase()+"/");

}

public boolean isInQOpenSys() {
return isInFileSystem("QOpenSys");
}

public boolean isInQsys() {
return isInFileSystem("qsys.lib");
}
public boolean isInQDLS() {
return isInFileSystem("qdls");
}

/**
Determines if the file is an IBM i "source physical file".
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/ibm/as400/access/IFSFileImplRemote.java
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,11 @@ public boolean isHidden()

return result;
}

private boolean isInQsys() {
String lowercasePath = fd_.path_.toLowerCase().replaceAll("//+","/");
return lowercasePath.equals("/qsys.lib") || lowercasePath.startsWith("/qsys.lib/");
}

/**
Determines if the integrated file system object represented by this
Expand Down Expand Up @@ -1827,6 +1832,12 @@ public boolean isSymbolicLink()
//
if (!determinedIsSymbolicLink_)
{
// QSYS doesn't support symbolic links, so no need to check
if(isInQsys()) {
isSymbolicLink_ = false;
determinedIsSymbolicLink_ = true;
return isSymbolicLink_;
}
// Note: As of V5R3, we can't get accurate symbolic link info by querying the attrs of a specific file.
// Instead, we must query the contents of the parent directory.
int pathLen = fd_.path_.length();
Expand Down

0 comments on commit 0d7f709

Please sign in to comment.