diff --git a/domain/src/main/java/org/cryptomator/domain/exception/FileRemovedDuringUploadException.java b/domain/src/main/java/org/cryptomator/domain/exception/FileRemovedDuringUploadException.java new file mode 100644 index 00000000..eb456f52 --- /dev/null +++ b/domain/src/main/java/org/cryptomator/domain/exception/FileRemovedDuringUploadException.java @@ -0,0 +1,7 @@ +package org.cryptomator.domain.exception; + +public class FileRemovedDuringUploadException extends BackendException { + + public FileRemovedDuringUploadException() { + } +} diff --git a/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadService.java b/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadService.java index 1ce3585a..b0b5feee 100644 --- a/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadService.java +++ b/presentation/src/main/java/org/cryptomator/presentation/service/AutoUploadService.java @@ -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 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); }