Skip to content

Commit ea67015

Browse files
committed
Fixed bug relaying file delete events in the getFileUpdates() method in the FileManager
1 parent b33fdba commit ea67015

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

src/javaxt/express/FileManager.java

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public javaxt.io.Directory getDirectory(){
6060
//**************************************************************************
6161
//** getFileUpdates
6262
//**************************************************************************
63-
/** Used to monitor the web directory for changes. Calls the eventMonitor
64-
* whenever a file is created, updated, moved or deleted. Example:
63+
/** Used to monitor the web directory for changes. Calls an EventMonitor
64+
* whenever a file is created, updated, moved, or deleted. Example:
6565
<pre>
6666
fileManager.getFileUpdates((Directory.Event event) -> {
6767
String op;
@@ -98,8 +98,18 @@ public void getFileUpdates(EventMonitor eventMonitor){
9898
}
9999

100100
try{
101-
java.io.File f = new java.io.File(event.getFile());
102-
if (f.isFile()) eventMonitor.processEvent(event);
101+
if (isValidPath(event.getFile())){
102+
if (event.getEventID()==Directory.Event.DELETE){
103+
eventMonitor.processEvent(event);
104+
}
105+
else{
106+
java.io.File f = new java.io.File(event.getFile());
107+
if (f.isFile() && !f.isHidden()){
108+
eventMonitor.processEvent(event);
109+
}
110+
}
111+
112+
}
103113
}
104114
catch(Exception e){}
105115
}
@@ -160,12 +170,7 @@ public java.io.File getFile(String path){
160170
for (String str : files){
161171

162172
//Ensure that the path doesn't have any illegal directives
163-
str = str.replace("\\", "/");
164-
if (str.contains("..") || str.contains("/.") ||
165-
str.toLowerCase().contains("/keystore")){
166-
continue;
167-
}
168-
173+
if (!isValidPath(str)) continue;
169174

170175

171176
//Send file if it exists
@@ -759,4 +764,19 @@ private String updateTag(Node node){
759764
return txt;
760765
}
761766

767+
768+
//**************************************************************************
769+
//** isValidPath
770+
//**************************************************************************
771+
/** Returns false if the given path contains illegal directives or to point
772+
* hidden or protected files.
773+
*/
774+
private static boolean isValidPath(String str){
775+
str = str.replace("\\", "/");
776+
if (str.contains("..") || str.contains("/.") ||
777+
str.toLowerCase().contains("/keystore")){
778+
return false;
779+
}
780+
return true;
781+
}
762782
}

0 commit comments

Comments
 (0)