Skip to content

Commit

Permalink
[FIXED JENKINS-12119] rolling back a portion of 46998ba0446834de0c725…
Browse files Browse the repository at this point in the history
…c32b328ace7ce844f6a as this is binary incompatible change
  • Loading branch information
kohsuke committed Jan 3, 2012
1 parent 867b67a commit 21244ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class="bug">
Fixed a bug in the symlink creation code on BSD platforms.
<a href="https://issues.jenkins-ci.org/browse/JENKINS-12119">issue 12119</a>
<li class="bug">
Incorrect path delimiter used in ZipArchiver when creating archive on Windows.
<a href="https://issues.jenkins-ci.org/browse/JENKINS-9942">issue 9942</a>
Expand Down
13 changes: 5 additions & 8 deletions core/src/main/java/hudson/Util.java
Expand Up @@ -991,32 +991,29 @@ public static void createSymlink(File baseDir, String targetPath, String symlink
// ignore a failure.
new LocalProc(new String[]{"rm","-rf", symlinkPath},new String[0],listener.getLogger(), baseDir).join();

int r = -1;
boolean operationDone = false;
Integer r=null;
if (!SYMLINK_ESCAPEHATCH) {
try {
r = LIBC.symlink(targetPath,symlinkFile.getAbsolutePath());
if (r!=0) {
r = Native.getLastError();
errmsg = LIBC.strerror(r);
}
operationDone = true;
} catch (LinkageError e) {
// if JNA is unavailable, fall back.
// we still prefer to try JNA first as PosixAPI supports even smaller platforms.
if (PosixAPI.isNative()) {
if (PosixAPI.supportsNative()) {
r = PosixAPI.get().symlink(targetPath,symlinkFile.getAbsolutePath());
operationDone = true;
}
}
}
if (!operationDone) {
// escape hatch, until we know that the above works well.
if (r==null) {
// if all else fail, fall back to the most expensive approach of forking a process
r = new LocalProc(new String[]{
"ln","-s", targetPath, symlinkPath},
new String[0],listener.getLogger(), baseDir).join();
}
if(r!=0)
if (r!=0)
listener.getLogger().println(String.format("ln -s %s %s failed: %d %s",targetPath, symlinkFile, r, errmsg));
} catch (IOException e) {
PrintStream log = listener.getLogger();
Expand Down
12 changes: 10 additions & 2 deletions core/src/main/java/hudson/os/PosixAPI.java
Expand Up @@ -21,14 +21,22 @@ public static POSIX get() {
return posix;
}

/**
* @deprecated as of 1.448
* Use {@link #supportsNative()}.
*/
public boolean isNative() {
return supportsNative();
}

/**
* Determine if the jna-posix library could not provide native support, and
* used a fallback java implementation which does not support many operations.
*/
public static boolean isNative() {
public static boolean supportsNative() {
return !(posix instanceof JavaPOSIX);
}

private static final POSIX posix = POSIXFactory.getPOSIX(new POSIXHandler() {
public void error(ERRORS errors, String s) {
throw new PosixException(s,errors);
Expand Down

0 comments on commit 21244ca

Please sign in to comment.