Skip to content

Commit

Permalink
Delete outdated libs as part of unpack()
Browse files Browse the repository at this point in the history
Summary: We might want different logic for different so sources.

Reviewed By: danjin250

Differential Revision: D49539327

fbshipit-source-id: fc868e95d0c0063efc1964f4c381c5483c3f9560
  • Loading branch information
adicatana authored and facebook-github-bot committed Oct 6, 2023
1 parent 9b0cfa6 commit ad4dc5a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
1 change: 1 addition & 0 deletions java/com/facebook/soloader/ExoSoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public Dso[] getDsos() throws IOException {
@Override
public void unpack(File soDirectory) throws IOException {
byte[] ioBuffer = new byte[32 * 1024];
deleteUnmentionedFiles(mDsos);
for (FileDso fileDso : mDsos) {
FileInputStream is = new FileInputStream(fileDso.backingFile);
try (InputDso inputDso = new InputDso(fileDso, is)) {
Expand Down
1 change: 1 addition & 0 deletions java/com/facebook/soloader/ExtractFromZipSoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public final Dso[] getDsos() throws IOException {
public void unpack(File soDirectory) throws IOException {
byte[] ioBuffer = new byte[32 * 1024];
ZipDso[] dsos = getExtractableDsosFromZip();
deleteUnmentionedFiles(dsos);
for (ZipDso zipDso : dsos) {
InputStream is = mZipFile.getInputStream(zipDso.backingEntry);
try (InputDso inputDso = new InputDso(zipDso, is)) {
Expand Down
10 changes: 2 additions & 8 deletions java/com/facebook/soloader/UnpackingSoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private static void writeState(File stateFileName, byte state, boolean runFsync)
}

/** Delete files not mentioned in the given DSO list. */
private void deleteUnmentionedFiles(Dso[] dsos) throws IOException {
protected void deleteUnmentionedFiles(Dso[] dsos) throws IOException {
String[] existingFiles = soDirectory.list();
if (existingFiles == null) {
throw new IOException("unable to list directory " + soDirectory);
Expand Down Expand Up @@ -169,6 +169,7 @@ private void deleteUnmentionedFiles(Dso[] dsos) throws IOException {
protected abstract static class Unpacker implements Closeable {
public abstract Dso[] getDsos() throws IOException;

/* Unpacks to soDirectory and removes existing outdated libs */
public abstract void unpack(File soDirectory) throws IOException;

@Override
Expand Down Expand Up @@ -358,17 +359,10 @@ private boolean refreshLocked(final FileLocker lock, final int flags) throws IOE
final boolean runFsync = ((flags & PREPARE_FLAG_DISABLE_FS_SYNC_JOB) == 0);
LogUtil.v(TAG, "so store dirty: regenerating");
writeState(stateFileName, STATE_DIRTY, runFsync);
Dso[] desiredDsos = null;
try (Unpacker u = makeUnpacker(forceUnpacking)) {
desiredDsos = u.getDsos();
deleteUnmentionedFiles(desiredDsos);
u.unpack(soDirectory);
}

if (desiredDsos == null) {
return false; // No sync needed
}

// N.B. We can afford to write the deps file without fsyncs because we've marked the DSO
// store STATE_DIRTY, which will cause us to ignore all intermediate state when regenerating it.
// That is, it's okay for the depsFile blocks to hit the disk before the actual DSO data file
Expand Down

0 comments on commit ad4dc5a

Please sign in to comment.