2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org
.spearce
.jgit
.util
;
40 import java
.io
.BufferedReader
;
42 import java
.io
.IOException
;
43 import java
.io
.InputStreamReader
;
44 import java
.security
.AccessController
;
45 import java
.security
.PrivilegedAction
;
47 class FS_Win32_Cygwin
extends FS_Win32
{
48 private static String cygpath
;
50 static boolean detect() {
51 final String path
= AccessController
52 .doPrivileged(new PrivilegedAction
<String
>() {
54 return System
.getProperty("java.library.path");
59 for (final String p
: path
.split(";")) {
60 final File e
= new File(p
, "cygpath.exe");
62 cygpath
= e
.getAbsolutePath();
69 protected File
resolveImpl(final File dir
, final String pn
) {
73 p
= Runtime
.getRuntime().exec(
74 new String
[] { cygpath
, "--windows", "--absolute", pn
},
76 p
.getOutputStream().close();
78 final BufferedReader lineRead
= new BufferedReader(
79 new InputStreamReader(p
.getInputStream(), "UTF-8"));
82 r
= lineRead
.readLine();
89 if (p
.waitFor() == 0 && r
!= null && r
.length() > 0)
92 } catch (InterruptedException ie
) {
93 // Stop bothering me, I have a zombie to reap.
96 } catch (IOException ioe
) {
97 // Fall through and use the default return.
100 return super.resolveImpl(dir
, pn
);
104 protected File
userHomeImpl() {
105 final String home
= AccessController
106 .doPrivileged(new PrivilegedAction
<String
>() {
107 public String
run() {
108 return System
.getenv("HOME");
111 if (home
== null || home
.length() == 0)
112 return super.userHomeImpl();
113 return resolveImpl(new File("."), home
);