diff --git a/src/main/java/com/ibm/as400/access/IFSFile.java b/src/main/java/com/ibm/as400/access/IFSFile.java index 8e5f7524..ab84984d 100644 --- a/src/main/java/com/ibm/as400/access/IFSFile.java +++ b/src/main/java/com/ibm/as400/access/IFSFile.java @@ -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 { @@ -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". diff --git a/src/main/java/com/ibm/as400/access/IFSFileImplRemote.java b/src/main/java/com/ibm/as400/access/IFSFileImplRemote.java index 22820106..a9797ac2 100644 --- a/src/main/java/com/ibm/as400/access/IFSFileImplRemote.java +++ b/src/main/java/com/ibm/as400/access/IFSFileImplRemote.java @@ -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 @@ -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();