1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-26 22:31:16 +00:00

Do not crash if folder does not exist (fixes #148).

This commit is contained in:
Felix Ableitner 2014-10-10 14:00:13 +03:00
parent 48188b845c
commit 47cc76a9fd
2 changed files with 24 additions and 2 deletions

View file

@ -270,7 +270,11 @@ public class SyncthingService extends Service {
public void onApiAvailable() { public void onApiAvailable() {
onApiChange(); onApiChange();
for (RestApi.Folder r : mApi.getFolders()) { for (RestApi.Folder r : mApi.getFolders()) {
try {
mObservers.add(new FolderObserver(mApi, r)); mObservers.add(new FolderObserver(mApi, r));
} catch (FolderObserver.FolderNotExistingException e) {
Log.w(TAG, e.getMessage());
}
} }
} }
}); });

View file

@ -32,6 +32,20 @@ public class FolderObserver extends FileObserver {
this(listener, folder, ""); 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. * 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); Log.v(TAG, "observer created for " + path + " in " + folder.ID);
startWatching(); 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 @Override
public boolean accept(File current, String name) { public boolean accept(File current, String name) {
return new File(current, name).isDirectory(); return new File(current, name).isDirectory();