Skip to content
This repository was archived by the owner on Jul 31, 2022. It is now read-only.

Commit bcab169

Browse files
committed
Fix watchload for file
1 parent 3d93dc3 commit bcab169

File tree

1 file changed

+6
-5
lines changed
  • src/main/java/com/kttdevelopment/simplehttpserver/handler

1 file changed

+6
-5
lines changed

src/main/java/com/kttdevelopment/simplehttpserver/handler/FileEntry.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class FileEntry {
3636
* @author Ktt Development
3737
*/
3838
FileEntry(final File file, final FileBytesAdapter bytesAdapter, final ByteLoadingOption loadingOption){
39-
this(file,bytesAdapter,loadingOption,true);
39+
this(file,bytesAdapter,loadingOption,false);
4040
}
4141

4242
/**
@@ -63,7 +63,8 @@ class FileEntry {
6363
if(!skipWatchService)
6464
try{
6565
final WatchService service = FileSystems.getDefault().newWatchService();
66-
final Path path = file.toPath();
66+
final Path target = file.toPath();
67+
final Path path = file.getParentFile().toPath();
6768
path.register(service,StandardWatchEventKinds.ENTRY_CREATE,StandardWatchEventKinds.ENTRY_DELETE,StandardWatchEventKinds.ENTRY_MODIFY);
6869

6970
new Thread(() -> {
@@ -72,10 +73,10 @@ class FileEntry {
7273
while((key = service.take()) != null){
7374
for(WatchEvent<?> event : key.pollEvents()){
7475
try{
75-
final Path target = (Path) event.context();
76+
final Path modified = path.resolve((Path) event.context());
7677
try{
77-
if(Files.isSameFile(path, target))
78-
preloadedBytes = bytesAdapter.getBytes(file,Files.readAllBytes(path));
78+
if(Files.isSameFile(target, modified))
79+
preloadedBytes = bytesAdapter.getBytes(file,Files.readAllBytes(target));
7980
}catch(final IOException ignored){ } // don't overwrite if corrupt
8081
}catch(final ClassCastException ignored){ }
8182
}

0 commit comments

Comments
 (0)