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

Commit ce272b4d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Create hard links to avoid copy (3/n)"

parents 9b8f383d 4da74962
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.content.rollback.PackageRollbackInfo;
import android.content.rollback.PackageRollbackInfo.RestoreInfo;
import android.content.rollback.RollbackInfo;
import android.os.UserHandle;
import android.system.ErrnoException;
import android.system.Os;
import android.util.AtomicFile;
import android.util.Slog;
import android.util.SparseIntArray;
@@ -237,9 +239,20 @@ class RollbackStore {
        targetDir.mkdirs();
        File targetFile = new File(targetDir, sourceFile.getName());

        // TODO: Copy by hard link instead to save on cpu and storage space?
        try {
            // Create a hard link to avoid copy
            // TODO(b/168562373)
            // Linking between non-encrypted and encrypted is not supported and we have
            // encrypted /data/rollback and non-encrypted /data/apex/active. For now this works
            // because we happen to store encrypted files under /data/apex/active which is no
            // longer the case when compressed apex rolls out. We have to handle this case in
            // order not to fall back to copy.
            Os.link(sourceFile.getAbsolutePath(), targetFile.getAbsolutePath());
        } catch (ErrnoException ignore) {
            // Fall back to copy if hardlink can't be created
            Files.copy(sourceFile.toPath(), targetFile.toPath());
        }
    }

    /**
     * Returns the apk or apex files backed up for the given package.