Skip to content
This repository has been archived by the owner on May 17, 2020. It is now read-only.

Commit

Permalink
Sync disks to prevent file corruption when users power-cycle their Pi…
Browse files Browse the repository at this point in the history
… Zeros soon after upload

Saw a few corrupted autostart files in the last weeks, which should be fixed by this.
  • Loading branch information
gohai committed May 27, 2016
1 parent 759dd16 commit 8c3351c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions resources/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ source.repository=https://github.com/gohai/processing-uploadtopi.git
# This is used to compare different versions of the same Tool, and check if an
# update is available.

tool.version=3
tool.version=4


# The version as the user will see it.

tool.prettyVersion=1.0.2
tool.prettyVersion=1.0.3


# The min and max revision of Processing compatible with your Tool.
Expand Down
24 changes: 23 additions & 1 deletion src/gohai/uploadtopi/UploadToPiTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,17 @@ public void run() {
return;
}

// XXX: sync since users might be inclined to power-cyle the Pi the hard way?
try {
editor.statusNotice("Syncing disks ...");
syncDisks();
} catch (Exception e) {
editor.statusError("Cannot sync disks");
// DEBUG
e.printStackTrace();
System.err.println(e);
disconnect();
return;
}

editor.statusNotice("Running " + sketchName + " on the Raspberry Pi");
try {
Expand Down Expand Up @@ -407,6 +417,18 @@ public void stopSketches() throws IOException {
}


public void syncDisks() throws IOException {
Session session = ssh.startSession();
Command cmd = session.exec("sync");
cmd.join(3, TimeUnit.SECONDS);
if (cmd.getExitStatus() != 0) {
// not critical
System.err.println("Error syncing disks. Make sure you power off the Pi safely to prevent file corruption.");
}
session.close();
}


public void uploadSketch(String localDir, String dest, String sketchName) throws IOException {
SFTPClient sftp = ssh.newSFTPClient();
// XXX: only upload changed files?
Expand Down

0 comments on commit 8c3351c

Please sign in to comment.