Skip to content

Commit 755b877

Browse files
committed
DO NOT MERGE Create intermediate directories when installing config data.
This prevents an issue where a user factory data resets and hoses the default directory layout- it will now be recreated on first update. Change-Id: I7e3cb47a0fa3aa941a74d46fba7e15865484b66d
1 parent b631084 commit 755b877

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

services/java/com/android/server/updatable/ConfigUpdateInstallReceiver.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,24 @@ private void writeUpdate(File dir, File file, String content) {
218218
try {
219219
// create the temporary file
220220
tmp = File.createTempFile("journal", "", dir);
221+
// create the parents for the destination file
222+
File parent = file.getParentFile();
223+
parent.mkdirs();
224+
// check that they were created correctly
225+
if (!parent.exists()) {
226+
throw new IOException("Failed to create directory " + parent.getCanonicalPath());
227+
}
221228
// mark tmp -rw-r--r--
222229
tmp.setReadable(true, false);
223230
// write to it
224231
out = new FileOutputStream(tmp);
225232
out.write(content.getBytes());
226233
// sync to disk
227-
FileUtils.sync(out);
234+
out.getFD().sync();
228235
// atomic rename
229-
tmp.renameTo(file);
236+
if (!tmp.renameTo(file)) {
237+
throw new IOException("Failed to atomically rename " + file.getCanonicalPath());
238+
}
230239
} catch (IOException e) {
231240
Slog.e(TAG, "Failed to write update", e);
232241
} finally {

0 commit comments

Comments
 (0)