Fixes #389 app crash when file deleted during auto upload

This commit is contained in:
Julian Raufelder 2021-11-16 20:45:57 +01:00
parent d5486463a8
commit c3278b3c25
No known key found for this signature in database
GPG Key ID: 17EE71F6634E381D
2 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1,7 @@
package org.cryptomator.domain.exception;
public class FileRemovedDuringUploadException extends BackendException {
public FileRemovedDuringUploadException() {
}
}

View File

@ -17,6 +17,7 @@ import org.cryptomator.domain.exception.BackendException;
import org.cryptomator.domain.exception.CancellationException;
import org.cryptomator.domain.exception.CloudNodeAlreadyExistsException;
import org.cryptomator.domain.exception.FatalBackendException;
import org.cryptomator.domain.exception.FileRemovedDuringUploadException;
import org.cryptomator.domain.exception.MissingCryptorException;
import org.cryptomator.domain.exception.NoSuchCloudFileException;
import org.cryptomator.domain.repository.CloudContentRepository;
@ -182,7 +183,11 @@ public class AutoUploadService extends Service {
} catch (CloudNodeAlreadyExistsException e) {
Timber.tag("AutoUploadService").i("Not uploading file because it already exists in the cloud");
Timber.tag("AutoUploadService").v(format("Not uploading file because it already exists in the cloud %s", file.getFileName()));
} catch (Exception e) {
} catch (FileRemovedDuringUploadException e) {
Timber.tag("AutoUploadService").i("Not uploading file because it was removed during upload");
Timber.tag("AutoUploadService").v(format("Not uploading file because it was removed during upload %s", file.getFileName()));
}
catch (Exception e) {
cancelled = true;
fileUtil.removeImagesFromAutoUploads(uploadedCloudFileNames);
throw e;
@ -211,6 +216,9 @@ public class AutoUploadService extends Service {
private CloudFile writeCloudFile(String fileName, CancelAwareDataSource dataSource, boolean replacing, ProgressAware<UploadState> progressAware) throws BackendException {
Long size = dataSource.size(context);
if(size == null) {
throw new FileRemovedDuringUploadException();
}
CloudFile source = cloudContentRepository.file(parent, fileName, size);
return cloudContentRepository.write(source, dataSource, progressAware, replacing, size);
}