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

Commit c35e55eb authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Attempt to unlink session file if hardlink fails" into udc-dev am:...

Merge "Attempt to unlink session file if hardlink fails" into udc-dev am: 7fbed032 am: 82105927 am: b1ac010c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/22959449



Change-Id: Ifde597ea0516eb05491fcdf10acdf9300a672f45
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 10628ffa b1ac010c
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -1645,13 +1645,14 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
            throw new SecurityException("link() can only be run by the system");
        }

        try {
        final File target = new File(path);
        final File source = new File(stageDir, target.getName());
        var sourcePath = source.getAbsolutePath();
        try {
            try {
                Os.link(path, source.getAbsolutePath());
                Os.link(path, sourcePath);
                // Grant READ access for APK to be read successfully
                Os.chmod(source.getAbsolutePath(), 0644);
                Os.chmod(sourcePath, 0644);
            } catch (ErrnoException e) {
                e.rethrowAsIOException();
            }
@@ -1659,6 +1660,12 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                throw new IOException("Can't relabel file: " + source);
            }
        } catch (IOException e) {
            try {
                Os.unlink(sourcePath);
            } catch (Exception ignored) {
                Slog.d(TAG, "Failed to unlink session file: " + sourcePath);
            }

            throw ExceptionUtils.wrap(e);
        }
    }