diff options
| author | 2023-05-04 21:12:04 +0000 | |
|---|---|---|
| committer | 2023-05-04 21:12:04 +0000 | |
| commit | 7fbed032f66d24e23f1bbb06c3e5094a73a06373 (patch) | |
| tree | ed45436b72c0cd782d300d38490d7305c07dce8f | |
| parent | cc87e369b8650e32882281b9ae16270b8d604324 (diff) | |
| parent | dd7ffddb26b5e75ef0a0127ef04e3f0c185c08ca (diff) | |
Merge "Attempt to unlink session file if hardlink fails" into udc-dev
| -rw-r--r-- | services/core/java/com/android/server/pm/PackageInstallerSession.java | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java index 97e7f6f41703..d3f7002e859f 100644 --- a/services/core/java/com/android/server/pm/PackageInstallerSession.java +++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java @@ -1645,13 +1645,14 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { throw new SecurityException("link() can only be run by the system"); } + final File target = new File(path); + final File source = new File(stageDir, target.getName()); + var sourcePath = source.getAbsolutePath(); try { - final File target = new File(path); - final File source = new File(stageDir, target.getName()); 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); } } |