|
@@ -87,8 +87,6 @@ import java.util.Set;
|
|
|
import java.util.UUID;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
-import static com.owncloud.android.utils.EncryptionUtils.encodeStringToBase64Bytes;
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* Operation performing the update in the ownCloud server
|
|
@@ -396,7 +394,6 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
File originalFile = new File(mOriginalStoragePath);
|
|
|
File expectedFile = null;
|
|
|
FileLock fileLock = null;
|
|
|
- long size = 0;
|
|
|
|
|
|
boolean metadataExists = false;
|
|
|
String token = null;
|
|
@@ -525,33 +522,11 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
String timeStamp = timeStampLong.toString();
|
|
|
|
|
|
|
|
|
- // Key
|
|
|
- byte[] key = null;
|
|
|
-
|
|
|
- try {
|
|
|
- // TODO change key if file has changed, e.g. when file is updated
|
|
|
- key = encodeStringToBase64Bytes(metadata.files.get(mFile.getFileName()).encrypted.key);
|
|
|
- } catch (Exception e) {
|
|
|
- // no key found
|
|
|
- }
|
|
|
-
|
|
|
- if (key == null || key.length == 0) {
|
|
|
- key = EncryptionUtils.generateKey();
|
|
|
- }
|
|
|
-
|
|
|
- // IV
|
|
|
- byte[] iv = null;
|
|
|
-
|
|
|
- try {
|
|
|
- iv = encodeStringToBase64Bytes(metadata.files.get(mFile.getFileName()).initializationVector);
|
|
|
- } catch (Exception e) {
|
|
|
- // no iv found
|
|
|
- }
|
|
|
-
|
|
|
- if (iv == null || iv.length == 0) {
|
|
|
- iv = EncryptionUtils.generateIV();
|
|
|
- }
|
|
|
+ // Key, always generate new one
|
|
|
+ byte[] key = EncryptionUtils.generateKey();
|
|
|
|
|
|
+ // IV, always generate new one
|
|
|
+ byte[] iv = EncryptionUtils.generateIV();
|
|
|
|
|
|
EncryptionUtils.EncryptedFile encryptedFile = EncryptionUtils.encryptFile(mFile, key, iv);
|
|
|
|
|
@@ -591,45 +566,6 @@ public class UploadFileOperation extends SyncOperation {
|
|
|
throw new OperationCancelledException();
|
|
|
}
|
|
|
|
|
|
-// FileChannel channel = null;
|
|
|
-// try {
|
|
|
-// channel = new RandomAccessFile(ocFile.getStoragePath(), "rw").getChannel();
|
|
|
-// fileLock = channel.tryLock();
|
|
|
-// } catch (FileNotFoundException e) {
|
|
|
-// if (temporalFile == null) {
|
|
|
-// String temporalPath = FileStorageUtils.getTemporalPath(account.name) + ocFile.getRemotePath();
|
|
|
-// ocFile.setStoragePath(temporalPath);
|
|
|
-// temporalFile = new File(temporalPath);
|
|
|
-//
|
|
|
-// result = copy(originalFile, temporalFile);
|
|
|
-//
|
|
|
-// if (result != null) {
|
|
|
-// return result;
|
|
|
-// } else {
|
|
|
-// if (temporalFile.length() == originalFile.length()) {
|
|
|
-// channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").getChannel();
|
|
|
-// fileLock = channel.tryLock();
|
|
|
-// } else {
|
|
|
-// while (temporalFile.length() != originalFile.length()) {
|
|
|
-// Files.deleteIfExists(Paths.get(temporalPath));
|
|
|
-// result = copy(originalFile, temporalFile);
|
|
|
-//
|
|
|
-// if (result != null) {
|
|
|
-// return result;
|
|
|
-// } else {
|
|
|
-// channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").
|
|
|
-// getChannel();
|
|
|
-// fileLock = channel.tryLock();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// channel = new RandomAccessFile(temporalFile.getAbsolutePath(), "rw").getChannel();
|
|
|
-// fileLock = channel.tryLock();
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
result = mUploadOperation.execute(client);
|
|
|
|
|
|
/// move local temporal file or original file to its corresponding
|