|
@@ -36,9 +36,14 @@ import java.nio.file.NoSuchFileException; |
|
|
import java.nio.file.Path; |
|
|
import java.nio.file.Path; |
|
|
import java.nio.file.Paths; |
|
|
import java.nio.file.Paths; |
|
|
import java.nio.file.StandardOpenOption; |
|
|
import java.nio.file.StandardOpenOption; |
|
|
|
|
|
import java.nio.file.attribute.FileAttribute; |
|
|
|
|
|
import java.nio.file.attribute.PosixFileAttributeView; |
|
|
|
|
|
import java.nio.file.attribute.PosixFilePermission; |
|
|
|
|
|
import java.nio.file.attribute.PosixFilePermissions; |
|
|
import java.text.DecimalFormat; |
|
|
import java.text.DecimalFormat; |
|
|
import java.util.ArrayList; |
|
|
import java.util.ArrayList; |
|
|
import java.util.Arrays; |
|
|
import java.util.Arrays; |
|
|
|
|
|
import java.util.EnumSet; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Locale; |
|
|
import java.util.Locale; |
|
|
import java.util.Optional; |
|
|
import java.util.Optional; |
|
@@ -100,6 +105,13 @@ public class FileUtils { |
|
|
*/ |
|
|
*/ |
|
|
public static final long NTFS_FILE_TIMESTAMP_GRANULARITY = 1; |
|
|
public static final long NTFS_FILE_TIMESTAMP_GRANULARITY = 1; |
|
|
|
|
|
|
|
|
|
|
|
private static final FileAttribute[] TMPFILE_ATTRIBUTES = |
|
|
|
|
|
new FileAttribute[] { |
|
|
|
|
|
PosixFilePermissions.asFileAttribute(EnumSet.of(PosixFilePermission.OWNER_READ, |
|
|
|
|
|
PosixFilePermission.OWNER_WRITE)) |
|
|
|
|
|
}; |
|
|
|
|
|
private static final FileAttribute[] NO_TMPFILE_ATTRIBUTES = new FileAttribute[0]; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* A one item cache for fromUri. |
|
|
* A one item cache for fromUri. |
|
|
* fromUri is called for each element when parsing ant build |
|
|
* fromUri is called for each element when parsing ant build |
|
@@ -893,6 +905,10 @@ public class FileUtils { |
|
|
* yield a different file name. |
|
|
* yield a different file name. |
|
|
* </p> |
|
|
* </p> |
|
|
* |
|
|
* |
|
|
|
|
|
* <p>If the filesystem where the temporary file is created |
|
|
|
|
|
* supports POSIX permissions, the file will only be readable and |
|
|
|
|
|
* writable by the current user.</p> |
|
|
|
|
|
* |
|
|
* @param prefix file name prefix. |
|
|
* @param prefix file name prefix. |
|
|
* @param suffix |
|
|
* @param suffix |
|
|
* file extension; include the '.'. |
|
|
* file extension; include the '.'. |
|
@@ -916,6 +932,10 @@ public class FileUtils { |
|
|
* exist before this method was invoked, any subsequent invocation |
|
|
* exist before this method was invoked, any subsequent invocation |
|
|
* of this method will yield a different file name.</p> |
|
|
* of this method will yield a different file name.</p> |
|
|
* |
|
|
* |
|
|
|
|
|
* <p>If the filesystem where the temporary file is created |
|
|
|
|
|
* supports POSIX permissions, the file will only be readable and |
|
|
|
|
|
* writable by the current user.</p> |
|
|
|
|
|
* |
|
|
* @param prefix file name prefix. |
|
|
* @param prefix file name prefix. |
|
|
* @param suffix file extension; include the '.'. |
|
|
* @param suffix file extension; include the '.'. |
|
|
* @param parentDir Directory to create the temporary file in; |
|
|
* @param parentDir Directory to create the temporary file in; |
|
@@ -947,6 +967,10 @@ public class FileUtils { |
|
|
* exist before this method was invoked, any subsequent invocation |
|
|
* exist before this method was invoked, any subsequent invocation |
|
|
* of this method will yield a different file name.</p> |
|
|
* of this method will yield a different file name.</p> |
|
|
* |
|
|
* |
|
|
|
|
|
* <p>If the filesystem where the temporary file is created |
|
|
|
|
|
* supports POSIX permissions, the file will only be readable and |
|
|
|
|
|
* writable by the current user.</p> |
|
|
|
|
|
* |
|
|
* @param project reference to the current Ant project. |
|
|
* @param project reference to the current Ant project. |
|
|
* @param prefix file name prefix. |
|
|
* @param prefix file name prefix. |
|
|
* @param suffix file extension; include the '.'. |
|
|
* @param suffix file extension; include the '.'. |
|
@@ -984,7 +1008,12 @@ public class FileUtils { |
|
|
|
|
|
|
|
|
if (createFile) { |
|
|
if (createFile) { |
|
|
try { |
|
|
try { |
|
|
result = File.createTempFile(prefix, suffix, new File(parent)); |
|
|
|
|
|
|
|
|
final Path parentPath = new File(parent).toPath(); |
|
|
|
|
|
final PosixFileAttributeView parentPosixAttributes = |
|
|
|
|
|
Files.getFileAttributeView(parentPath, PosixFileAttributeView.class); |
|
|
|
|
|
result = Files.createTempFile(parentPath, prefix, suffix, |
|
|
|
|
|
parentPosixAttributes != null ? TMPFILE_ATTRIBUTES : NO_TMPFILE_ATTRIBUTES) |
|
|
|
|
|
.toFile(); |
|
|
} catch (IOException e) { |
|
|
} catch (IOException e) { |
|
|
throw new BuildException("Could not create tempfile in " |
|
|
throw new BuildException("Could not create tempfile in " |
|
|
+ parent, e); |
|
|
+ parent, e); |
|
@@ -1015,6 +1044,10 @@ public class FileUtils { |
|
|
* yield a different file name. |
|
|
* yield a different file name. |
|
|
* </p> |
|
|
* </p> |
|
|
* |
|
|
* |
|
|
|
|
|
* <p>If the filesystem where the temporary file is created |
|
|
|
|
|
* supports POSIX permissions, the file will only be readable and |
|
|
|
|
|
* writable by the current user.</p> |
|
|
|
|
|
* |
|
|
* @param prefix file name prefix. |
|
|
* @param prefix file name prefix. |
|
|
* @param suffix |
|
|
* @param suffix |
|
|
* file extension; include the '.'. |
|
|
* file extension; include the '.'. |
|
|