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

Commit 0b2fa8ca authored by Kenny Root's avatar Kenny Root
Browse files

Don't prematurely delete temporary files

When verification and encryption is used, the temporary file was deleted
prematurely.

Also, on next boot-up, scan the directory we use for temporary files to
clean them up if the user rebooted in the middle of installation.

Bug: 7132197
Change-Id: Ic9e8aab9a664ca00d9ac16f72e53fc43d78d21bc
parent 34186480
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -6334,7 +6334,8 @@ public class PackageManagerService extends IPackageManager.Stub {
                            packageFile = mTempPackage;

                            FileUtils.setPermissions(packageFile.getAbsolutePath(),
                                    FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IROTH,
                                    FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP
                                            | FileUtils.S_IROTH,
                                    -1, -1);
                        } else {
                            packageFile = null;
@@ -6515,12 +6516,12 @@ public class PackageManagerService extends IPackageManager.Stub {
            // will succeed.
            if (mArgs != null) {
                processPendingInstall(mArgs, mRet);
            }

                if (mTempPackage != null) {
                    if (!mTempPackage.delete()) {
                    Slog.w(TAG, "Couldn't delete temporary file: "
                            + mTempPackage.getAbsolutePath());
                        Slog.w(TAG, "Couldn't delete temporary file: " +
                                mTempPackage.getAbsolutePath());
                    }
                }
            }
        }
@@ -7942,17 +7943,23 @@ public class PackageManagerService extends IPackageManager.Stub {
    }

    private void deleteTempPackageFiles() {
        FilenameFilter filter = new FilenameFilter() {
        final FilenameFilter filter = new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.startsWith("vmdl") && name.endsWith(".tmp");
            }
        };
        String tmpFilesList[] = mAppInstallDir.list(filter);
        deleteTempPackageFilesInDirectory(mAppInstallDir, filter);
        deleteTempPackageFilesInDirectory(mDrmAppPrivateInstallDir, filter);
    }

    private static final void deleteTempPackageFilesInDirectory(File directory,
            FilenameFilter filter) {
        final String[] tmpFilesList = directory.list(filter);
        if (tmpFilesList == null) {
            return;
        }
        for (int i = 0; i < tmpFilesList.length; i++) {
            File tmpFile = new File(mAppInstallDir, tmpFilesList[i]);
            final File tmpFile = new File(directory, tmpFilesList[i]);
            tmpFile.delete();
        }
    }