Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix HER-1979 so heritrix can run on windows xp #23

Merged
merged 1 commit into from
Dec 18, 2013
Merged
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
37 changes: 26 additions & 11 deletions commons/src/main/java/org/archive/util/FilesystemLinkMaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.archive.util;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;

import com.sun.jna.Native;
import com.sun.jna.Platform;
Expand All @@ -34,6 +35,8 @@
*/
public class FilesystemLinkMaker {

private static final Logger logger = Logger.getLogger(FilesystemLinkMaker.class.getName());

// see https://github.com/twall/jna/blob/master/www/GettingStarted.md
public interface Kernel32Library extends StdCallLibrary {
Kernel32Library INSTANCE = (Kernel32Library) (Platform.isWindows()
Expand Down Expand Up @@ -75,26 +78,38 @@ public static class LPSECURITY_ATTRIBUTES extends Structure {
*/
// XXX could handle errors better (examine errno, throw exception...)
public static boolean makeHardLink(String existingPath, String newPath) {
if (Platform.isWindows()) {
return Kernel32Library.INSTANCE.CreateHardLinkA(newPath, existingPath, null);
} else {
int status = CLibrary.INSTANCE.link(existingPath, newPath);
return status == 0;
try {
if (Platform.isWindows()) {
return Kernel32Library.INSTANCE.CreateHardLinkA(newPath, existingPath, null);
} else {
int status = CLibrary.INSTANCE.link(existingPath, newPath);
return status == 0;
}
} catch (UnsatisfiedLinkError e) {
// see https://webarchive.jira.com/browse/HER-1979
logger.warning("hard links not supported on this platform - " + e);
return false;
}
}

/**
* Wrapper over platform-dependent system calls to create a symboic link.
* Wrapper over platform-dependent system calls to create a symbolic link.
*
* @return true on success
*/
// XXX could handle errors better (examine errno, throw exception...)
public static boolean makeSymbolicLink(String existingPath, String newPath) {
if (Platform.isWindows()) {
return Kernel32Library.INSTANCE.CreateSymbolicLinkA(newPath, existingPath, null);
} else {
int status = CLibrary.INSTANCE.symlink(existingPath, newPath);
return status == 0;
try {
if (Platform.isWindows()) {
return Kernel32Library.INSTANCE.CreateSymbolicLinkA(newPath, existingPath, null);
} else {
int status = CLibrary.INSTANCE.symlink(existingPath, newPath);
return status == 0;
}
} catch (UnsatisfiedLinkError e) {
// see https://webarchive.jira.com/browse/HER-1979
logger.warning("symbolic links not supported on this platform - " + e);
return false;
}
}

Expand Down