/** * Convert a path to String, replacing separators as necessary. * * @param file * a {@link java.io.File}. * @return file's path as a String * @since 4.10 */ public static String pathToString(File file) { final String path = file.getPath(); if (SystemReader.getInstance().isWindows()) { return path.replace('\\', '/'); } return path; } }
private static File getSymRef(File workTree, File dotGit, FS fs) throws IOException { byte[] content = IO.readFully(dotGit); if (!isSymRef(content)) throw new IOException(MessageFormat.format( JGitText.get().invalidGitdirRef, dotGit.getAbsolutePath())); int pathStart = 8; int lineEnd = RawParseUtils.nextLF(content, pathStart); while (content[lineEnd - 1] == '\n' || (content[lineEnd - 1] == '\r' && SystemReader.getInstance().isWindows())) lineEnd--; if (lineEnd == pathStart) throw new IOException(MessageFormat.format( JGitText.get().invalidGitdirRef, dotGit.getAbsolutePath())); String gitdirPath = RawParseUtils.decode(content, pathStart, lineEnd); File gitdirFile = fs.resolve(workTree, gitdirPath); if (gitdirFile.isAbsolute()) return gitdirFile; else return new File(workTree, gitdirPath).getCanonicalFile(); }
/** * Read target path of the symlink. * * @param path * a {@link java.io.File} object. * @return target path of the symlink, or null if it is not a symbolic link * @throws java.io.IOException * @since 3.0 */ public static String readSymLink(File path) throws IOException { Path nioPath = toPath(path); Path target = Files.readSymbolicLink(nioPath); String targetString = target.toString(); if (SystemReader.getInstance().isWindows()) { targetString = targetString.replace('\\', '/'); } else if (SystemReader.getInstance().isMacOS()) { targetString = Normalizer.normalize(targetString, Form.NFC); } return targetString; }
private static EolStreamType getOutputFormat(WorkingTreeOptions options) { switch (options.getAutoCRLF()) { case TRUE: return EolStreamType.TEXT_CRLF; default: // no decision } switch (options.getEOL()) { case CRLF: return EolStreamType.TEXT_CRLF; case NATIVE: if (SystemReader.getInstance().isWindows()) { return EolStreamType.TEXT_CRLF; } return EolStreamType.TEXT_LF; case LF: default: break; } return EolStreamType.DIRECT; }
/** * Should be used in tests when the platform is explicitly changed. * * @since 3.6 */ protected final void setPlatformChecker() { platformChecker = new ObjectChecker() .setSafeForWindows(isWindows()) .setSafeForMacOS(isMacOS()); }
/** * Detect the file system * * @param cygwinUsed * @return FS instance */ public FS detect(Boolean cygwinUsed) { if (SystemReader.getInstance().isWindows()) { if (cygwinUsed == null) cygwinUsed = Boolean.valueOf(FS_Win32_Cygwin.isCygwin()); if (cygwinUsed.booleanValue()) return new FS_Win32_Cygwin(); else return new FS_Win32(); } else { return new FS_POSIX(); } } }
/** * Create a symbolic link * * @param path * the path of the symbolic link to create * @param target * the target of the symbolic link * @return the path to the symbolic link * @throws java.io.IOException * @since 4.2 */ public static Path createSymLink(File path, String target) throws IOException { Path nioPath = toPath(path); if (Files.exists(nioPath, LinkOption.NOFOLLOW_LINKS)) { BasicFileAttributes attrs = Files.readAttributes(nioPath, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); if (attrs.isRegularFile() || attrs.isSymbolicLink()) { delete(path); } else { delete(path, EMPTY_DIRECTORIES_ONLY | RECURSIVE); } } if (SystemReader.getInstance().isWindows()) { target = target.replace('/', '\\'); } Path nioTarget = toPath(new File(target)); return Files.createSymbolicLink(nioPath, nioTarget); }
@SuppressWarnings("deprecation") private static void checkValidPath(CanonicalTreeParser t) throws InvalidPathException { ObjectChecker chk = new ObjectChecker() .setSafeForWindows(SystemReader.getInstance().isWindows()) .setSafeForMacOS(SystemReader.getInstance().isMacOS()); for (CanonicalTreeParser i = t; i != null; i = i.getParent()) checkValidPathSegment(chk, i); }
false); safeForWindows = rc.getBoolean(FSCK, "safeForWindows", SystemReader.getInstance().isWindows()); safeForMacOS = rc.getBoolean(FSCK, "safeForMacOS", SystemReader.getInstance().isMacOS());
public static void createSymLink(File path, String target) throws IOException { Path nioPath = path.toPath(); if (Files.exists(nioPath, LinkOption.NOFOLLOW_LINKS)) Files.delete(nioPath); if (SystemReader.getInstance().isWindows()) target = target.replace('/', '\\'); Path nioTarget = new File(target).toPath(); Files.createSymbolicLink(nioPath, nioTarget); }
public static void createSymLink(File path, String target) throws IOException { Path nioPath = path.toPath(); if (Files.exists(nioPath, LinkOption.NOFOLLOW_LINKS)) Files.delete(nioPath); if (SystemReader.getInstance().isWindows()) target = target.replace('/', '\\'); Path nioTarget = new File(target).toPath(); Files.createSymbolicLink(nioPath, nioTarget); }
/** * Convert a path to String, replacing separators as necessary. * * @param file * a {@link java.io.File}. * @return file's path as a String * @since 4.10 */ public static String pathToString(File file) { final String path = file.getPath(); if (SystemReader.getInstance().isWindows()) { return path.replace('\\', '/'); } return path; } }
static String readSymlink(File path) throws IOException { Path nioPath = path.toPath(); Path target = Files.readSymbolicLink(nioPath); String targetString = target.toString(); if (SystemReader.getInstance().isWindows()) targetString = targetString.replace('\\', '/'); else if (SystemReader.getInstance().isMacOS()) targetString = Normalizer.normalize(targetString, Form.NFC); return targetString; }
static String readSymlink(File path) throws IOException { Path nioPath = path.toPath(); Path target = Files.readSymbolicLink(nioPath); String targetString = target.toString(); if (SystemReader.getInstance().isWindows()) targetString = targetString.replace('\\', '/'); else if (SystemReader.getInstance().isMacOS()) targetString = Normalizer.normalize(targetString, Form.NFC); return targetString; }
@Override public FS detect(Boolean cygwinUsed) { if (SystemReader.getInstance().isWindows()) { if (cygwinUsed == null) cygwinUsed = Boolean.valueOf(FS_Win32_Cygwin.isCygwin()); if (cygwinUsed.booleanValue()) return new FS_Win32_Java7Cygwin(); else return new FS_Win32_Java7(); } else return new FS_POSIX_Java7(); } }
@Override public FS detect(Boolean cygwinUsed) { if (SystemReader.getInstance().isWindows()) { if (cygwinUsed == null) cygwinUsed = Boolean.valueOf(FS_Win32_Cygwin.isCygwin()); if (cygwinUsed.booleanValue()) return new FS_Win32_Java7Cygwin(); else return new FS_Win32_Java7(); } else return new FS_POSIX_Java7(); } }
/** * Should be used in tests when the platform is explicitly changed. * * @since 3.6 */ protected final void setPlatformChecker() { platformChecker = new ObjectChecker() .setSafeForWindows(isWindows()) .setSafeForMacOS(isMacOS()); }
/** * Should be used in tests when the platform is explicitly changed. * * @since 3.6 */ protected final void setPlatformChecker() { platformChecker = new ObjectChecker() .setSafeForWindows(isWindows()) .setSafeForMacOS(isMacOS()); }
@SuppressWarnings("deprecation") private static void checkValidPath(CanonicalTreeParser t) throws InvalidPathException { ObjectChecker chk = new ObjectChecker() .setSafeForWindows(SystemReader.getInstance().isWindows()) .setSafeForMacOS(SystemReader.getInstance().isMacOS()); for (CanonicalTreeParser i = t; i != null; i = i.getParent()) checkValidPathSegment(chk, i); }
@SuppressWarnings("deprecation") private static void checkValidPath(CanonicalTreeParser t) throws InvalidPathException { ObjectChecker chk = new ObjectChecker() .setSafeForWindows(SystemReader.getInstance().isWindows()) .setSafeForMacOS(SystemReader.getInstance().isMacOS()); for (CanonicalTreeParser i = t; i != null; i = i.getParent()) checkValidPathSegment(chk, i); }