mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-30 00:01:19 +00:00
Do not crash if folder does not exist (fixes #148).
This commit is contained in:
parent
48188b845c
commit
47cc76a9fd
2 changed files with 24 additions and 2 deletions
|
@ -270,7 +270,11 @@ public class SyncthingService extends Service {
|
|||
public void onApiAvailable() {
|
||||
onApiChange();
|
||||
for (RestApi.Folder r : mApi.getFolders()) {
|
||||
try {
|
||||
mObservers.add(new FolderObserver(mApi, r));
|
||||
} catch (FolderObserver.FolderNotExistingException e) {
|
||||
Log.w(TAG, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -32,6 +32,20 @@ public class FolderObserver extends FileObserver {
|
|||
this(listener, folder, "");
|
||||
}
|
||||
|
||||
public class FolderNotExistingException extends RuntimeException {
|
||||
|
||||
private String mPath;
|
||||
|
||||
public FolderNotExistingException(String path) {
|
||||
mPath = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "Path " + mPath + " does not exist, aborting file observer";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs watcher and starts watching the given directory recursively.
|
||||
*
|
||||
|
@ -49,7 +63,11 @@ public class FolderObserver extends FileObserver {
|
|||
Log.v(TAG, "observer created for " + path + " in " + folder.ID);
|
||||
startWatching();
|
||||
|
||||
File[] directories = new File(folder.Path, path).listFiles(new FilenameFilter() {
|
||||
File currentFolder = new File(folder.Path, path);
|
||||
if (!currentFolder.exists()) {
|
||||
throw new FolderNotExistingException(currentFolder.getAbsolutePath());
|
||||
}
|
||||
File[] directories = currentFolder.listFiles(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File current, String name) {
|
||||
return new File(current, name).isDirectory();
|
||||
|
|
Loading…
Reference in a new issue