Skip to content

Commit d0aa5d4

Browse files
remove FileStorageUtils.getTemporalPath()
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent bd780c5 commit d0aa5d4

File tree

14 files changed

+85
-62
lines changed

14 files changed

+85
-62
lines changed

src/androidTest/java/com/nextcloud/client/EndToEndRandomIT.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,15 @@ private void downloadFile(int i) {
378378
public void testUploadWithCopy() throws Exception {
379379
init();
380380

381-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
381+
OCUpload ocUpload = new OCUpload(FileStorageUtils.getInternalTemporalPath(account.name, targetContext)
382+
+ "/nonEmpty.txt",
382383
currentFolder.getRemotePath() + "nonEmpty.txt",
383384
account.name);
384385

385386
uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_COPY);
386387

387-
File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
388+
File originalFile = new File(FileStorageUtils.getInternalTemporalPath(account.name, targetContext)
389+
+ "/nonEmpty.txt");
388390
OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(currentFolder.getRemotePath() +
389391
"nonEmpty.txt");
390392

@@ -396,13 +398,15 @@ public void testUploadWithCopy() throws Exception {
396398
public void testUploadWithMove() throws Exception {
397399
init();
398400

399-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
401+
OCUpload ocUpload = new OCUpload(FileStorageUtils.getInternalTemporalPath(account.name, targetContext)
402+
+ "/nonEmpty.txt",
400403
currentFolder.getRemotePath() + "nonEmpty.txt",
401404
account.name);
402405

403406
uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_MOVE);
404407

405-
File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
408+
File originalFile = new File(FileStorageUtils.getInternalTemporalPath(account.name, targetContext)
409+
+ "/nonEmpty.txt");
406410
OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(currentFolder.getRemotePath() +
407411
"nonEmpty.txt");
408412

@@ -414,13 +418,15 @@ public void testUploadWithMove() throws Exception {
414418
public void testUploadWithForget() throws Exception {
415419
init();
416420

417-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
421+
OCUpload ocUpload = new OCUpload(FileStorageUtils.getInternalTemporalPath(account.name, targetContext)
422+
+ "/nonEmpty.txt",
418423
currentFolder.getRemotePath() + "nonEmpty.txt",
419424
account.name);
420425

421426
uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_FORGET);
422427

423-
File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
428+
File originalFile = new File(FileStorageUtils.getInternalTemporalPath(account.name, targetContext)
429+
+ "/nonEmpty.txt");
424430
OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(currentFolder.getRemotePath() +
425431
"nonEmpty.txt");
426432

@@ -432,13 +438,15 @@ public void testUploadWithForget() throws Exception {
432438
public void testUploadWithDelete() throws Exception {
433439
init();
434440

435-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
441+
OCUpload ocUpload = new OCUpload(FileStorageUtils.getInternalTemporalPath(account.name, targetContext)
442+
+ "/nonEmpty.txt",
436443
currentFolder.getRemotePath() + "nonEmpty.txt",
437444
account.name);
438445

439446
uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_DELETE);
440447

441-
File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
448+
File originalFile = new File(FileStorageUtils.getInternalTemporalPath(account.name, targetContext)
449+
+ "/nonEmpty.txt");
442450
OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(currentFolder.getRemotePath() +
443451
"nonEmpty.txt");
444452

src/androidTest/java/com/owncloud/android/AbstractIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ protected Account[] getAllAccounts() {
205205
}
206206

207207
protected static void createDummyFiles() throws IOException {
208-
File tempPath = new File(FileStorageUtils.getTemporalPath(account.name));
208+
File tempPath = new File(FileStorageUtils.getInternalTemporalPath(account.name, targetContext));
209209
if (!tempPath.exists()) {
210210
assertTrue(tempPath.mkdirs());
211211
}

src/androidTest/java/com/owncloud/android/DownloadIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,15 @@ public void after() {
7373

7474
@Test
7575
public void verifyDownload() {
76-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
76+
OCUpload ocUpload = new OCUpload(FileStorageUtils.getInternalTemporalPath(account.name, targetContext)
77+
+ "/nonEmpty.txt",
7778
FOLDER + "nonEmpty.txt",
7879
account.name);
7980

8081
uploadOCUpload(ocUpload);
8182

82-
OCUpload ocUpload2 = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
83+
OCUpload ocUpload2 = new OCUpload(FileStorageUtils.getInternalTemporalPath(account.name, targetContext)
84+
+ "/nonEmpty.txt",
8385
FOLDER + "nonEmpty2.txt",
8486
account.name);
8587

src/androidTest/java/com/owncloud/android/UploadIT.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
import androidx.annotation.NonNull;
4848

49+
import static com.owncloud.android.utils.FileStorageUtils.getInternalTemporalPath;
4950
import static junit.framework.TestCase.assertEquals;
5051
import static junit.framework.TestCase.assertFalse;
5152
import static junit.framework.TestCase.assertTrue;
@@ -122,7 +123,7 @@ public void after() {
122123

123124
@Test
124125
public void testEmptyUpload() {
125-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
126+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/empty.txt",
126127
FOLDER + "empty.txt",
127128
account.name);
128129

@@ -131,7 +132,7 @@ public void testEmptyUpload() {
131132

132133
@Test
133134
public void testNonEmptyUpload() {
134-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
135+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/nonEmpty.txt",
135136
FOLDER + "nonEmpty.txt",
136137
account.name);
137138

@@ -140,13 +141,13 @@ public void testNonEmptyUpload() {
140141

141142
@Test
142143
public void testUploadWithCopy() {
143-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
144+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/nonEmpty.txt",
144145
FOLDER + "nonEmpty.txt",
145146
account.name);
146147

147148
uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_COPY);
148149

149-
File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
150+
File originalFile = new File(getInternalTemporalPath(account.name, targetContext) + "/nonEmpty.txt");
150151
OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
151152

152153
assertTrue(originalFile.exists());
@@ -156,13 +157,13 @@ public void testUploadWithCopy() {
156157

157158
@Test
158159
public void testUploadWithMove() {
159-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
160+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/nonEmpty.txt",
160161
FOLDER + "nonEmpty.txt",
161162
account.name);
162163

163164
uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_MOVE);
164165

165-
File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
166+
File originalFile = new File(getInternalTemporalPath(account.name, targetContext) + "/nonEmpty.txt");
166167
OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
167168

168169
assertFalse(originalFile.exists());
@@ -172,13 +173,13 @@ public void testUploadWithMove() {
172173

173174
@Test
174175
public void testUploadWithForget() {
175-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
176+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/nonEmpty.txt",
176177
FOLDER + "nonEmpty.txt",
177178
account.name);
178179

179180
uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_FORGET);
180181

181-
File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
182+
File originalFile = new File(getInternalTemporalPath(account.name, targetContext) + "/nonEmpty.txt");
182183
OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
183184

184185
assertTrue(originalFile.exists());
@@ -188,13 +189,13 @@ public void testUploadWithForget() {
188189

189190
@Test
190191
public void testUploadWithDelete() {
191-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt",
192+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/nonEmpty.txt",
192193
FOLDER + "nonEmpty.txt",
193194
account.name);
194195

195196
uploadOCUpload(ocUpload, FileUploader.LOCAL_BEHAVIOUR_DELETE);
196197

197-
File originalFile = new File(FileStorageUtils.getTemporalPath(account.name) + "/nonEmpty.txt");
198+
File originalFile = new File(getInternalTemporalPath(account.name, targetContext) + "/nonEmpty.txt");
198199
OCFile uploadedFile = fileDataStorageManager.getFileByDecryptedRemotePath(FOLDER + "nonEmpty.txt");
199200

200201
assertFalse(originalFile.exists());
@@ -204,23 +205,23 @@ public void testUploadWithDelete() {
204205

205206
@Test
206207
public void testChunkedUpload() {
207-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/chunkedFile.txt",
208+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/chunkedFile.txt",
208209
FOLDER + "chunkedFile.txt", account.name);
209210

210211
uploadOCUpload(ocUpload);
211212
}
212213

213214
@Test
214215
public void testUploadInNonExistingFolder() {
215-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
216+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/empty.txt",
216217
FOLDER + "2/3/4/1.txt", account.name);
217218

218219
uploadOCUpload(ocUpload);
219220
}
220221

221222
@Test
222223
public void testUploadOnChargingOnlyButNotCharging() {
223-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
224+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/empty.txt",
224225
FOLDER + "notCharging.txt", account.name);
225226
ocUpload.setWhileChargingOnly(true);
226227

@@ -268,7 +269,7 @@ public BatteryStatus getBattery() {
268269
}
269270
};
270271

271-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
272+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/empty.txt",
272273
FOLDER + "charging.txt", account.name);
273274
ocUpload.setWhileChargingOnly(true);
274275

@@ -308,7 +309,7 @@ public Connectivity getConnectivity() {
308309
return new Connectivity(true, false, false, true);
309310
}
310311
};
311-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
312+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/empty.txt",
312313
FOLDER + "noWifi.txt", account.name);
313314
ocUpload.setUseWifiOnly(true);
314315

@@ -338,7 +339,7 @@ public Connectivity getConnectivity() {
338339

339340
@Test
340341
public void testUploadOnWifiOnlyAndWifi() {
341-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
342+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/empty.txt",
342343
FOLDER + "wifi.txt", account.name);
343344
ocUpload.setWhileChargingOnly(true);
344345

@@ -387,7 +388,7 @@ public Connectivity getConnectivity() {
387388
return new Connectivity(true, true, true, true);
388389
}
389390
};
390-
OCUpload ocUpload = new OCUpload(FileStorageUtils.getTemporalPath(account.name) + "/empty.txt",
391+
OCUpload ocUpload = new OCUpload(getInternalTemporalPath(account.name, targetContext) + "/empty.txt",
391392
FOLDER + "noWifi.txt",
392393
account.name);
393394
ocUpload.setUseWifiOnly(true);

src/androidTest/java/com/owncloud/android/utils/FileUtilTest.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ class FileUtilTest : AbstractIT() {
4343

4444
@Test
4545
fun assertSlashInput() {
46-
val tempPath = File(FileStorageUtils.getTemporalPath(account.name) + File.pathSeparator + "folder")
46+
val tempPath = File(
47+
FileStorageUtils.getInternalTemporalPath(account.name, targetContext) +
48+
File.pathSeparator + "folder"
49+
)
4750
if (!tempPath.exists()) {
4851
Assert.assertTrue(tempPath.mkdirs())
4952
}
@@ -58,7 +61,7 @@ class FileUtilTest : AbstractIT() {
5861

5962
@Test
6063
fun assertFolderInput() {
61-
val tempPath = File(FileStorageUtils.getTemporalPath(account.name))
64+
val tempPath = File(FileStorageUtils.getInternalTemporalPath(account.name, targetContext))
6265
if (!tempPath.exists()) {
6366
Assert.assertTrue(tempPath.mkdirs())
6467
}

src/androidTest/java/com/owncloud/android/utils/SyncedFolderUtilsTest.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
package com.owncloud.android.utils
2222

23+
import androidx.test.platform.app.InstrumentationRegistry
2324
import com.owncloud.android.AbstractIT
2425
import com.owncloud.android.datamodel.MediaFolder
2526
import com.owncloud.android.datamodel.MediaFolderType
@@ -195,7 +196,9 @@ class SyncedFolderUtilsTest : AbstractIT() {
195196
getDummyFile(THUMBNAILS_FOLDER + File.separatorChar + IMAGE_JPEG)
196197
getDummyFile(THUMBNAILS_FOLDER + File.separatorChar + IMAGE_BITMAP)
197198
val folder = SyncedFolder(
198-
FileStorageUtils.getTemporalPath(account.name) + File.separatorChar + THUMBNAILS_FOLDER,
199+
FileStorageUtils.getInternalTemporalPath(account.name, targetContext)
200+
+ File.separatorChar
201+
+ THUMBNAILS_FOLDER,
199202
"",
200203
true,
201204
false,
@@ -232,8 +235,11 @@ class SyncedFolderUtilsTest : AbstractIT() {
232235
fun setUp() {
233236
val tempPath =
234237
File(
235-
FileStorageUtils.getTemporalPath(account.name) + File.separatorChar +
236-
THUMBNAILS_FOLDER
238+
FileStorageUtils.getInternalTemporalPath(
239+
account.name,
240+
InstrumentationRegistry.getInstrumentation().getTargetContext()
241+
) + File.separatorChar
242+
+ THUMBNAILS_FOLDER
237243
)
238244
if (!tempPath.exists()) {
239245
tempPath.mkdirs()
@@ -257,7 +263,14 @@ class SyncedFolderUtilsTest : AbstractIT() {
257263
@AfterClass
258264
@JvmStatic
259265
fun tearDown() {
260-
FileUtils.deleteDirectory(File(FileStorageUtils.getTemporalPath(account.name)))
266+
FileUtils.deleteDirectory(
267+
File(
268+
FileStorageUtils.getInternalTemporalPath(
269+
account.name,
270+
InstrumentationRegistry.getInstrumentation().targetContext
271+
)
272+
)
273+
)
261274
}
262275
}
263276
}

src/main/java/com/nextcloud/client/jobs/AccountRemovalWork.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class AccountRemovalWork(
201201
}
202202

203203
private fun removeFiles(user: User, storageManager: FileDataStorageManager) {
204-
val tempDir = File(FileStorageUtils.getTemporalPath(user.accountName))
204+
val tempDir = File(FileStorageUtils.getInternalTemporalPath(user.accountName, context))
205205
val saveDir = File(FileStorageUtils.getSavePath(user.accountName))
206206
FileStorageUtils.deleteRecursively(tempDir, storageManager)
207207
FileStorageUtils.deleteRecursively(saveDir, storageManager)

src/main/java/com/owncloud/android/operations/DownloadFileOperation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ public String getSavePath() {
105105
}
106106

107107
public String getTmpPath() {
108-
return FileStorageUtils.getTemporalPath(user.getAccountName()) + file.getRemotePath();
108+
return FileStorageUtils.getInternalTemporalPath(user.getAccountName(), context) + file.getRemotePath();
109109
}
110110

111111
public String getTmpFolder() {
112-
return FileStorageUtils.getTemporalPath(user.getAccountName());
112+
return FileStorageUtils.getInternalTemporalPath(user.getAccountName(), context);
113113
}
114114

115115
public String getRemotePath() {

src/main/java/com/owncloud/android/operations/RenameFileOperation.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
package com.owncloud.android.operations;
2323

24+
import android.content.Context;
2425
import android.text.TextUtils;
2526

2627
import com.owncloud.android.datamodel.FileDataStorageManager;
@@ -46,20 +47,25 @@ public class RenameFileOperation extends SyncOperation {
4647
private static final String TAG = RenameFileOperation.class.getSimpleName();
4748

4849
private OCFile file;
49-
private String remotePath;
50-
private String newName;
50+
private final String remotePath;
51+
private final String newName;
52+
private Context context;
5153

5254
/**
5355
* Constructor
5456
*
5557
* @param remotePath RemotePath of the OCFile instance describing the remote file or folder to rename
5658
* @param newName New name to set as the name of file.
5759
*/
58-
public RenameFileOperation(String remotePath, String newName, FileDataStorageManager storageManager) {
60+
public RenameFileOperation(String remotePath,
61+
String newName,
62+
FileDataStorageManager storageManager,
63+
Context context) {
5964
super(storageManager);
6065

6166
this.remotePath = remotePath;
6267
this.newName = newName;
68+
this.context = context;
6369
}
6470

6571
/**
@@ -172,7 +178,7 @@ private boolean isValidNewName() throws IOException {
172178
return false;
173179
}
174180
// create a test file
175-
String tmpFolderName = FileStorageUtils.getTemporalPath("");
181+
String tmpFolderName = FileStorageUtils.getInternalTemporalPath("", context);
176182
File testFile = new File(tmpFolderName + newName);
177183
File tmpFolder = testFile.getParentFile();
178184
if (! tmpFolder.mkdirs()) {

0 commit comments

Comments
 (0)