diff options
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java | 90 |
1 files changed, 18 insertions, 72 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java index 1c113617f8..db2b5b4f71 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/FS_POSIX.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, Robin Rosenberg and others + * Copyright (C) 2010, 2024, Robin Rosenberg and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -203,7 +203,16 @@ public class FS_POSIX extends FS { /** {@inheritDoc} */ @Override public boolean canExecute(File f) { - return FileUtils.canExecute(f); + if (!isFile(f)) { + return false; + } + try { + Path path = FileUtils.toPath(f); + Set<PosixFilePermission> pset = Files.getPosixFilePermissions(path); + return pset.contains(PosixFilePermission.OWNER_EXECUTE); + } catch (IOException ex) { + return false; + } } /** {@inheritDoc} */ @@ -250,8 +259,12 @@ public class FS_POSIX extends FS { /** {@inheritDoc} */ @Override public ProcessBuilder runInShell(String cmd, String[] args) { - List<String> argv = new ArrayList<>(4 + args.length); + List<String> argv = new ArrayList<>(5 + args.length); argv.add("sh"); //$NON-NLS-1$ + if (SystemReader.getInstance().isMacOS()) { + // Use a login shell to get the full normal $PATH + argv.add("-l"); //$NON-NLS-1$ + } argv.add("-c"); //$NON-NLS-1$ argv.add(cmd + " \"$@\""); //$NON-NLS-1$ argv.add(cmd); @@ -328,73 +341,6 @@ public class FS_POSIX extends FS { return supportsAtomicFileCreation == AtomicFileCreation.SUPPORTED; } - @Override - @SuppressWarnings("boxing") - /** - * {@inheritDoc} - * <p> - * An implementation of the File#createNewFile() semantics which works also - * on NFS. If the config option - * {@code core.supportsAtomicCreateNewFile = true} (which is the default) - * then simply File#createNewFile() is called. - * - * But if {@code core.supportsAtomicCreateNewFile = false} then after - * successful creation of the lock file a hard link to that lock file is - * created and the attribute nlink of the lock file is checked to be 2. If - * multiple clients manage to create the same lock file nlink would be - * greater than 2 showing the error. - * - * @see "https://www.time-travellers.org/shane/papers/NFS_considered_harmful.html" - * - * @deprecated use {@link FS_POSIX#createNewFileAtomic(File)} instead - * @since 4.5 - */ - @Deprecated - public boolean createNewFile(File lock) throws IOException { - if (!lock.createNewFile()) { - return false; - } - if (supportsAtomicCreateNewFile()) { - return true; - } - Path lockPath = lock.toPath(); - Path link = null; - FileStore store = null; - try { - store = Files.getFileStore(lockPath); - } catch (SecurityException e) { - return true; - } - try { - Boolean canLink = CAN_HARD_LINK.computeIfAbsent(store, - s -> Boolean.TRUE); - if (Boolean.FALSE.equals(canLink)) { - return true; - } - link = Files.createLink( - Paths.get(lock.getAbsolutePath() + ".lnk"), //$NON-NLS-1$ - lockPath); - Integer nlink = (Integer) (Files.getAttribute(lockPath, - "unix:nlink")); //$NON-NLS-1$ - if (nlink > 2) { - LOG.warn(MessageFormat.format( - JGitText.get().failedAtomicFileCreation, lockPath, - nlink)); - return false; - } else if (nlink < 2) { - CAN_HARD_LINK.put(store, Boolean.FALSE); - } - return true; - } catch (UnsupportedOperationException | IllegalArgumentException e) { - CAN_HARD_LINK.put(store, Boolean.FALSE); - return true; - } finally { - if (link != null) { - Files.delete(link); - } - } - } - /** * {@inheritDoc} * <p> @@ -418,6 +364,7 @@ public class FS_POSIX extends FS { * @return LockToken this lock token must be held until the file is no * longer needed * @throws IOException + * if an IO error occurred * @since 5.0 */ @Override @@ -446,8 +393,7 @@ public class FS_POSIX extends FS { return token(true, null); } link = Files.createLink(Paths.get(uniqueLinkPath(file)), path); - Integer nlink = (Integer) (Files.getAttribute(path, - "unix:nlink")); //$NON-NLS-1$ + Integer nlink = (Integer) Files.getAttribute(path, "unix:nlink"); //$NON-NLS-1$ if (nlink.intValue() > 2) { LOG.warn(MessageFormat.format( JGitText.get().failedAtomicFileCreation, path, nlink)); |