ToolsInstaller: write to temporary file, fsync, rename
Reported-by: Andre Christanto <christantoandre@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
2694f48b87
commit
d40ac7f89d
@ -54,6 +54,7 @@ public final class SharedLibraryLoader {
|
|||||||
while ((len = in.read(buffer)) != -1) {
|
while ((len = in.read(buffer)) != -1) {
|
||||||
out.write(buffer, 0, len);
|
out.write(buffer, 0, len);
|
||||||
}
|
}
|
||||||
|
out.getFD().sync();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -149,18 +149,22 @@ public final class ToolsInstaller {
|
|||||||
public boolean extract() throws IOException {
|
public boolean extract() throws IOException {
|
||||||
localBinaryDir.mkdirs();
|
localBinaryDir.mkdirs();
|
||||||
final File files[] = new File[EXECUTABLES.length];
|
final File files[] = new File[EXECUTABLES.length];
|
||||||
|
final File tempFiles[] = new File[EXECUTABLES.length];
|
||||||
boolean allExist = true;
|
boolean allExist = true;
|
||||||
for (int i = 0; i < files.length; ++i) {
|
for (int i = 0; i < files.length; ++i) {
|
||||||
files[i] = new File(localBinaryDir, EXECUTABLES[i]);
|
files[i] = new File(localBinaryDir, EXECUTABLES[i]);
|
||||||
|
tempFiles[i] = new File(localBinaryDir, EXECUTABLES[i] + ".tmp");
|
||||||
allExist &= files[i].exists();
|
allExist &= files[i].exists();
|
||||||
}
|
}
|
||||||
if (allExist)
|
if (allExist)
|
||||||
return false;
|
return false;
|
||||||
for (int i = 0; i < files.length; ++i) {
|
for (int i = 0; i < files.length; ++i) {
|
||||||
if (!SharedLibraryLoader.extractLibrary(context, EXECUTABLES[i], files[i]))
|
if (!SharedLibraryLoader.extractLibrary(context, EXECUTABLES[i], tempFiles[i]))
|
||||||
throw new FileNotFoundException("Unable to find " + EXECUTABLES[i]);
|
throw new FileNotFoundException("Unable to find " + EXECUTABLES[i]);
|
||||||
if (!files[i].setExecutable(true, false))
|
if (!tempFiles[i].setExecutable(true, false))
|
||||||
throw new IOException("Unable to mark " + files[i].getAbsolutePath() + " as executable");
|
throw new IOException("Unable to mark " + tempFiles[i].getAbsolutePath() + " as executable");
|
||||||
|
if (!tempFiles[i].renameTo(files[i]))
|
||||||
|
throw new IOException("Unable to rename " + tempFiles[i].getAbsolutePath() + " to " + files[i].getAbsolutePath());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user