mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1237576 - DownloadAction: Remove canWrite() check. r=rnewman
We can't use File.canWrite() on files that do not exist yet. After all we are going to create the file in a folder that we just created. So it is very unlikely that writing to that folder is going to fail.
This commit is contained in:
parent
e4b518fd11
commit
e7f0ce101d
@ -87,11 +87,6 @@ public class DownloadAction extends BaseAction {
|
|||||||
|
|
||||||
temporaryFile = createTemporaryFile(context, content);
|
temporaryFile = createTemporaryFile(context, content);
|
||||||
|
|
||||||
if (!canWrite(temporaryFile, destinationFile)) {
|
|
||||||
throw new RecoverableDownloadContentException(RecoverableDownloadContentException.DISK_IO,
|
|
||||||
"Temporary or destination file not writeable");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasEnoughDiskSpace(content, destinationFile, temporaryFile)) {
|
if (!hasEnoughDiskSpace(content, destinationFile, temporaryFile)) {
|
||||||
Log.d(LOGTAG, "Not enough disk space to save content. Skipping download.");
|
Log.d(LOGTAG, "Not enough disk space to save content. Skipping download.");
|
||||||
continue;
|
continue;
|
||||||
@ -341,14 +336,4 @@ public class DownloadAction extends BaseAction {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean canWrite(File... files) {
|
|
||||||
for (File file : files) {
|
|
||||||
if (!file.canWrite()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,6 @@ public class TestDownloadAction {
|
|||||||
doReturn(file).when(action).createTemporaryFile(RuntimeEnvironment.application, content);
|
doReturn(file).when(action).createTemporaryFile(RuntimeEnvironment.application, content);
|
||||||
doReturn(file).when(action).getDestinationFile(RuntimeEnvironment.application, content);
|
doReturn(file).when(action).getDestinationFile(RuntimeEnvironment.application, content);
|
||||||
|
|
||||||
doReturn(true).when(action).canWrite(any(File.class), any(File.class));
|
|
||||||
doReturn(false).when(action).verify(eq(file), anyString());
|
doReturn(false).when(action).verify(eq(file), anyString());
|
||||||
doNothing().when(action).download(any(HttpClient.class), anyString(), eq(file));
|
doNothing().when(action).download(any(HttpClient.class), anyString(), eq(file));
|
||||||
doReturn(true).when(action).verify(eq(file), anyString());
|
doReturn(true).when(action).verify(eq(file), anyString());
|
||||||
@ -203,7 +202,6 @@ public class TestDownloadAction {
|
|||||||
|
|
||||||
DownloadAction action = spy(new DownloadAction(null));
|
DownloadAction action = spy(new DownloadAction(null));
|
||||||
doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application);
|
doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application);
|
||||||
doReturn(true).when(action).canWrite(any(File.class), any(File.class));
|
|
||||||
|
|
||||||
File temporaryFile = mockFileWithSize(1337L);
|
File temporaryFile = mockFileWithSize(1337L);
|
||||||
doReturn(temporaryFile).when(action).createTemporaryFile(RuntimeEnvironment.application, content);
|
doReturn(temporaryFile).when(action).createTemporaryFile(RuntimeEnvironment.application, content);
|
||||||
@ -303,7 +301,6 @@ public class TestDownloadAction {
|
|||||||
File destinationFile = mockNotExistingFile();
|
File destinationFile = mockNotExistingFile();
|
||||||
doReturn(destinationFile).when(action).getDestinationFile(RuntimeEnvironment.application, content);
|
doReturn(destinationFile).when(action).getDestinationFile(RuntimeEnvironment.application, content);
|
||||||
|
|
||||||
doReturn(true).when(action).canWrite(any(File.class), any(File.class));
|
|
||||||
doReturn(true).when(action).verify(eq(temporaryFile), anyString());
|
doReturn(true).when(action).verify(eq(temporaryFile), anyString());
|
||||||
doNothing().when(action).extract(eq(temporaryFile), eq(destinationFile), anyString());
|
doNothing().when(action).extract(eq(temporaryFile), eq(destinationFile), anyString());
|
||||||
|
|
||||||
@ -336,7 +333,6 @@ public class TestDownloadAction {
|
|||||||
|
|
||||||
DownloadAction action = spy(new DownloadAction(null));
|
DownloadAction action = spy(new DownloadAction(null));
|
||||||
doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application);
|
doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application);
|
||||||
doReturn(true).when(action).canWrite(any(File.class), any(File.class));
|
|
||||||
doNothing().when(action).download(any(HttpClient.class), anyString(), any(File.class));
|
doNothing().when(action).download(any(HttpClient.class), anyString(), any(File.class));
|
||||||
doReturn(false).when(action).verify(any(File.class), anyString());
|
doReturn(false).when(action).verify(any(File.class), anyString());
|
||||||
|
|
||||||
@ -447,7 +443,6 @@ public class TestDownloadAction {
|
|||||||
doReturn(mockNotExistingFile()).when(action).createTemporaryFile(RuntimeEnvironment.application, content);
|
doReturn(mockNotExistingFile()).when(action).createTemporaryFile(RuntimeEnvironment.application, content);
|
||||||
doReturn(mockNotExistingFile()).when(action).getDestinationFile(RuntimeEnvironment.application, content);
|
doReturn(mockNotExistingFile()).when(action).getDestinationFile(RuntimeEnvironment.application, content);
|
||||||
doReturn(true).when(action).hasEnoughDiskSpace(eq(content), any(File.class), any(File.class));
|
doReturn(true).when(action).hasEnoughDiskSpace(eq(content), any(File.class), any(File.class));
|
||||||
doReturn(true).when(action).canWrite(any(File.class), any(File.class));
|
|
||||||
|
|
||||||
HttpClient client = mock(HttpClient.class);
|
HttpClient client = mock(HttpClient.class);
|
||||||
doThrow(IOException.class).when(client).execute(any(HttpUriRequest.class));
|
doThrow(IOException.class).when(client).execute(any(HttpUriRequest.class));
|
||||||
@ -504,32 +499,6 @@ public class TestDownloadAction {
|
|||||||
verify(catalog, times(11)).rememberFailure(eq(content), anyInt());
|
verify(catalog, times(11)).rememberFailure(eq(content), anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Scenario: Temporary or destination file is not writable.
|
|
||||||
*
|
|
||||||
* Verify that:
|
|
||||||
* * No download is performed
|
|
||||||
* * Error is counted as failure
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testNoDownIsPerformedIfFilesAreNotWritable() throws Exception{
|
|
||||||
DownloadContent content = createFont();
|
|
||||||
DownloadContentCatalog catalog = mockCatalogWithScheduledDownloads(content);
|
|
||||||
|
|
||||||
DownloadAction action = spy(new DownloadAction(null));
|
|
||||||
doReturn(true).when(action).isConnectedToNetwork(RuntimeEnvironment.application);
|
|
||||||
doReturn(false).when(action).isActiveNetworkMetered(RuntimeEnvironment.application);
|
|
||||||
doReturn(mockNotExistingFile()).when(action).createTemporaryFile(RuntimeEnvironment.application, content);
|
|
||||||
doReturn(mockNotExistingFile()).when(action).getDestinationFile(RuntimeEnvironment.application, content);
|
|
||||||
doReturn(false).when(action).canWrite(any(File.class), any(File.class));
|
|
||||||
|
|
||||||
action.perform(RuntimeEnvironment.application, catalog);
|
|
||||||
|
|
||||||
verify(action).canWrite(any(File.class), any(File.class));
|
|
||||||
verify(action, never()).download(any(HttpClient.class), anyString(), any(File.class));
|
|
||||||
verify(catalog).rememberFailure(eq(content), anyInt());
|
|
||||||
}
|
|
||||||
|
|
||||||
private DownloadContent createFont() {
|
private DownloadContent createFont() {
|
||||||
return createFontWithSize(102400L);
|
return createFontWithSize(102400L);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user