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

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

Change-Id: I8c0b63b8aa1eaf14ca29de63b5ea338092e65c48
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Treehugger Robot
2023-05-04 23:47:05 +00:00
committed by Automerger Merge Worker

View File

@@ -1645,13 +1645,14 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
throw new SecurityException("link() can only be run by the system"); 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 { try {
final File target = new File(path);
final File source = new File(stageDir, target.getName());
try { try {
Os.link(path, source.getAbsolutePath()); Os.link(path, sourcePath);
// Grant READ access for APK to be read successfully // Grant READ access for APK to be read successfully
Os.chmod(source.getAbsolutePath(), 0644); Os.chmod(sourcePath, 0644);
} catch (ErrnoException e) { } catch (ErrnoException e) {
e.rethrowAsIOException(); e.rethrowAsIOException();
} }
@@ -1659,6 +1660,12 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
throw new IOException("Can't relabel file: " + source); throw new IOException("Can't relabel file: " + source);
} }
} catch (IOException e) { } catch (IOException e) {
try {
Os.unlink(sourcePath);
} catch (Exception ignored) {
Slog.d(TAG, "Failed to unlink session file: " + sourcePath);
}
throw ExceptionUtils.wrap(e); throw ExceptionUtils.wrap(e);
} }
} }