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

Commit dd7ffddb authored by Winson Chiu's avatar Winson Chiu
Browse files

Attempt to unlink session file if hardlink fails

If either creating the link or changing the file permissions fails, the session
should clean up the link so that a fallback manual copy can succeed. This can occur
during APEX rollback.

Bug: 274802935

Test: manual, follow steps in bug to test rollback mechanism

Change-Id: Ic15bbe657a11a26b4bbcc48dca2f3e3a3f1239e2
parent 45d3fa60
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -1633,13 +1633,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();
            }
@@ -1647,6 +1648,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);
        }
    }