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

Commit 4da74962 authored by JW Wang's avatar JW Wang
Browse files

Create hard links to avoid copy (3/n)

Bug: 168562373
Test: atest CtsRollbackManagerTestCases CtsRollbackManagerHostTestCases
Test: atest StagedRollbackTest

Change-Id: I7a2f68079e026e326262a3f5e4cd2c024a6165c1
parent 7e4e0acc
Loading
Loading
Loading
Loading
+15 −2
Original line number Original line Diff line number Diff line
@@ -25,6 +25,8 @@ import android.content.rollback.PackageRollbackInfo;
import android.content.rollback.PackageRollbackInfo.RestoreInfo;
import android.content.rollback.PackageRollbackInfo.RestoreInfo;
import android.content.rollback.RollbackInfo;
import android.content.rollback.RollbackInfo;
import android.os.UserHandle;
import android.os.UserHandle;
import android.system.ErrnoException;
import android.system.Os;
import android.util.AtomicFile;
import android.util.AtomicFile;
import android.util.Slog;
import android.util.Slog;
import android.util.SparseIntArray;
import android.util.SparseIntArray;
@@ -237,9 +239,20 @@ class RollbackStore {
        targetDir.mkdirs();
        targetDir.mkdirs();
        File targetFile = new File(targetDir, sourceFile.getName());
        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());
            Files.copy(sourceFile.toPath(), targetFile.toPath());
        }
        }
    }


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