Skip to content

Commit

Permalink
added RSYNC4J_HOME environment variable support on Windows for custom…
Browse files Browse the repository at this point in the history
… location of binaries and keys
  • Loading branch information
fracpete committed Jan 7, 2018
1 parent 676b7d1 commit 132f018
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Add the following artifact to your dependencies of your `pom.xml`:
<dependency>
<groupId>com.github.fracpete</groupId>
<artifactId>rsync4j</artifactId>
<version>3.1.2-5</version>
<version>3.1.2-6</version>
</dependency>
```

Expand Down Expand Up @@ -338,11 +338,18 @@ Will get automatically get converted to:
/cygdrive/c/some/path/blah.txt
```

### Custom location

It is possible to use another location than `%USERPROFILE%\rsync4j`. You only
have to set up the `RSYNC4J_HOME` environment variable to point to the top-level
directory (doesn't have to exist) where you want to house the binaries and keys.


## FAQ

* **Q** I'm trying to sync, but it just sits there and does nothing!
* **A** Since *rsync4j* is not interactive, you will have to connect to the
remote host at least once before to add the host the `known_hosts` file.
remote host at least once before to add the host to the `known_hosts` file.
* **Q** How do I use a specific public key pair?
* **A** You can let `ssh` know what identity file to use using rsync's `--rsh`
option and ssh's `-i` option, e.g.: `rsync --rsh="ssh -i /some/where/id_rsa" ...`
Expand Down
33 changes: 30 additions & 3 deletions src/main/java/com/github/fracpete/rsync4j/Binaries.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/**
/*
* Binaries.java
* Copyright (C) 2017 University of Waikato, Hamilton, New Zealand
* Copyright (C) 2017-2018 University of Waikato, Hamilton, New Zealand
*/

package com.github.fracpete.rsync4j;
Expand Down Expand Up @@ -46,6 +46,9 @@ public class Binaries {
/** the sub-directory for the windows binaries. */
public final static String WINDOWS_DIR = "windows-x86_64/";

/** the windows environment variable for the rsyncj4 home directory. */
public final static String WINDOWS_HOME_DIR = "RSYNC4J_HOME";

/** for storing any previously extract binary. */
protected static Boolean binariesExtracted;

Expand Down Expand Up @@ -128,6 +131,30 @@ protected static String copyResourceTo(String inDir, String name, String outDir)
return result;
}

/**
* Returns the home directory to use for rsync4j.
* On Windows, use the {@link #WINDOWS_HOME_DIR} environment variable
* to point it to a custom location.
*
* @return the directory
*/
protected static String homeDir() {
String result;
File dir;

result = System.getProperty("user.home") + File.separator + "rsync4j";

if (SystemUtils.IS_OS_WINDOWS) {
if (System.getenv(WINDOWS_HOME_DIR) != null) {
dir = new File(System.getenv(WINDOWS_HOME_DIR));
if (!dir.exists() || dir.isDirectory())
result = dir.getAbsolutePath();
}
}

return result;
}

/**
* Extracts the binaries to the tmp directory.
*
Expand All @@ -152,7 +179,7 @@ protected static void extractBinaries() throws Exception {
throw new IllegalStateException("ssh not installed (" + sshBinary + ")?");
}
else if (SystemUtils.IS_OS_WINDOWS) {
homeDir = System.getProperty("user.home") + File.separator + "rsync4j";
homeDir = homeDir();
binDir = homeDir + File.separator + "bin";
sshDir = homeDir + File.separator + "home" + File.separator + System.getProperty("user.name") + File.separator + ".ssh";
if (!new File(binDir + File.separator + "rsync.exe").exists()) {
Expand Down

0 comments on commit 132f018

Please sign in to comment.