Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,8 @@ private void onReceiveCancel() {
if (st != null && st.phase == SyncTransferState.Phase.TRANSFERRING) {
syncVm.stopPull(); // K2GO-576: first, so no new chunk starts after the sweep below
transport.stop();
// After stopPull the marker is final: present only when the pull started to write.
cloneGuardHeld = org.appdevforall.k2go.InstallGuard.isLive(requireContext());
releaseCloneEnv(false); // ADFA-4956: overwrite aborted mid-pull, drop lock
syncVm.releaseNetwork();
SyncProgressRepository.get().postIdle();
Expand Down Expand Up @@ -1327,8 +1329,8 @@ private void startReceiveTransfer() {
// tree. releaseCloneEnv() on the terminal state boots the replaced system back.
EnvironmentLock.acquire(app, EnvironmentLock.Owner.CLONE);
cloneLockHeld = true;
org.appdevforall.k2go.InstallGuard.begin(app);
cloneGuardHeld = true;
// The InstallGuard marker comes with the first write (onWriteStarting): a pull that fails
// before it, for example on an old pairing code, leaves the library intact.
SyncProgressRepository.get().postTransferring(0, "", "", "RootFS");
final String destPath = dest.getAbsolutePath();
final SyncHandshakeHelper.SyncCredentials fcreds = creds;
Expand All @@ -1343,6 +1345,7 @@ private void startReceiveTransfer() {
// K2GO-576: the pull runs on Wi-Fi and the cable at once (ChunkedPull lists, then splits).
syncVm.startPull(app, shareConfig, fcreds, destPath,
new TransportEngine.SyncListener() {
@Override public void onWriteStarting() { org.appdevforall.k2go.InstallGuard.begin(app); }
@Override public void onProgress(int pct, String speed, String eta, String file) { SyncProgressRepository.get().postTransferring(pct, speed, eta, file); }
@Override public void onComplete(String message) {
// The local rootfs is now the other device's, so anything this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ public void start() {
}

public void stop() {
cancelled = true;
synchronized (this) { // with the onWriteStarting call in run()
cancelled = true;
}
ChunkQueue q = queue;
if (q != null) q.cancel();
for (Process p : processes) p.destroy();
Expand All @@ -142,6 +144,12 @@ private void run() {
}
queue = new ChunkQueue(TransferChunk.plan(files, CHUNK_BYTES, CHUNK_FILES));
Log.i(TAG, files.size() + " files, " + queue.totalBytes() + " bytes to copy");
// The list is a dry-run. From here rsync writes into the tree. Under the lock, so that after
// stop() returns the call has either finished or will not come.
synchronized (this) {
if (cancelled) return;
listener.onWriteStarting();
}

long lastPathAt = 0;
long lastDone = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ interface SyncListener {
void onComplete(String message);

void onError(String error);

/**
* The pull is about to write into the destination for the first time. Before this, a failure
* leaves the destination as it was. Called once, on the pull thread, before the first write.
*/
default void onWriteStarting() {
}
}

/** Callback for the dry-run transfer-size estimate. */
Expand Down
Loading