Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 755b8774 authored by Geremy Condra's avatar Geremy Condra
Browse files

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
parent b6310846
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -218,15 +218,24 @@ public class ConfigUpdateInstallReceiver extends BroadcastReceiver {
        try {
            // create the temporary file
            tmp = File.createTempFile("journal", "", dir);
            // create the parents for the destination file
            File parent = file.getParentFile();
            parent.mkdirs();
            // check that they were created correctly
            if (!parent.exists()) {
                throw new IOException("Failed to create directory " + parent.getCanonicalPath());
            }
            // mark tmp -rw-r--r--
            tmp.setReadable(true, false);
            // write to it
            out = new FileOutputStream(tmp);
            out.write(content.getBytes());
            // sync to disk
            FileUtils.sync(out);
            out.getFD().sync();
            // atomic rename
            tmp.renameTo(file);
            if (!tmp.renameTo(file)) {
                throw new IOException("Failed to atomically rename " + file.getCanonicalPath());
            }
        } catch (IOException e) {
            Slog.e(TAG, "Failed to write update", e);
        } finally {