~ubuntu-branches/ubuntu/trusty/jenkins/trusty

« back to all changes in this revision

Viewing changes to core/src/main/java/hudson/util/jna/Kernel32Utils.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-13 12:35:19 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20130813123519-tizgfxcr70trl7r0
Tags: 1.509.2+dfsg-1
* New upstream release (Closes: #706725):
  - d/control: Update versioned BD's:
    * jenkins-executable-war >= 1.28.
    * jenkins-instance-identity >= 1.3.
    * libjenkins-remoting-java >= 2.23.
    * libjenkins-winstone-java >= 0.9.10-jenkins-44.
    * libstapler-java >= 1.207.
    * libjenkins-json-java >= 2.4-jenkins-1.
    * libstapler-adjunct-timeline-java >= 1.4.
    * libstapler-adjunct-codemirror-java >= 1.2.
    * libmaven-hpi-plugin-java >= 1.93.
    * libjenkins-xstream-java >= 1.4.4-jenkins-3.
  - d/maven.rules: Map to older version of animal-sniffer-maven-plugin.
  - Add patch for compatibility with guava >= 0.14.
  - Add patch to exclude asm4 dependency via jnr-posix.
  - Fixes the following security vulnerabilities:
    CVE-2013-2034, CVE-2013-2033, CVE-2013-2034, CVE-2013-1808
* d/patches/*: Switch to using git patch-queue for managing patches.
* De-duplicate jars between libjenkins-java and jenkins-external-job-monitor
  (Closes: #701163):
  - d/control: Add dependency between jenkins-external-job-monitor ->
    libjenkins-java.
  - d/rules: 
    Drop installation of jenkins-core in jenkins-external-job-monitor.
  - d/jenkins-external-job-monitor.{links,install}: Link to jenkins-core
    in /usr/share/java instead of included version.
* Wait longer for jenkins to stop during restarts (Closes: #704848):
  - d/jenkins.init: Re-sync init script from upstream codebase.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    }
59
59
 
60
60
    public static int getWin32FileAttributes(File file) throws IOException {
61
 
      return Kernel32.INSTANCE.GetFileAttributesW(new WString(file.getCanonicalPath()));
 
61
        // allow lookup of paths longer than MAX_PATH
 
62
        // http://msdn.microsoft.com/en-us/library/aa365247(v=VS.85).aspx
 
63
        String canonicalPath = file.getCanonicalPath();
 
64
        String path;
 
65
        if(canonicalPath.length() < 260) {
 
66
                // path is short, use as-is
 
67
                path = canonicalPath;
 
68
        } else if(canonicalPath.startsWith("\\\\")) {
 
69
                // network share
 
70
                // \\server\share --> \\?\UNC\server\share
 
71
                path = "\\\\?\\UNC\\" + canonicalPath.substring(2);
 
72
        } else {
 
73
                // prefix, canonical path should be normalized and absolute so this should work.
 
74
                path = "\\\\?\\" + canonicalPath;
 
75
        }
 
76
      return Kernel32.INSTANCE.GetFileAttributesW(new WString(path));
 
77
    }
 
78
 
 
79
    /**
 
80
     * @param target
 
81
     *      If relative, resolved against the location of the symlink.
 
82
     *      If absolute, it's absolute.
 
83
     * @throws UnsatisfiedLinkError
 
84
     *      If the function is not exported by kernel32.
 
85
     *      See http://msdn.microsoft.com/en-us/library/windows/desktop/aa363866(v=vs.85).aspx
 
86
     *      for compatibility info.
 
87
     */
 
88
    public static void createSymbolicLink(File symlink, String target, boolean dirLink) throws IOException {
 
89
        if (!Kernel32.INSTANCE.CreateSymbolicLinkW(
 
90
                new WString(symlink.getPath()), new WString(target),
 
91
                dirLink?Kernel32.SYMBOLIC_LINK_FLAG_DIRECTORY:0)) {
 
92
            throw new WinIOException("Failed to create a symlink "+symlink+" to "+target);
 
93
        }
62
94
    }
63
95
 
64
96
    public static boolean isJunctionOrSymlink(File file) throws IOException {
65
 
      return (file.exists() && (Kernel32.FILE_ATTRIBUTE_REPARSE_POINT & getWin32FileAttributes(file)) != 0);
 
97
        return (file.exists() && (Kernel32.FILE_ATTRIBUTE_REPARSE_POINT & getWin32FileAttributes(file)) != 0);
66
98
    }
67
99
 
68
100
    /*package*/ static Kernel32 load() {