use of org.gradle.internal.file.FileMetadata.AccessType in project gradle by gradle.
the class NativePlatformBackedFileMetadataAccessor method stat.
@Override
public FileMetadata stat(File f) {
FileInfo stat;
try {
stat = files.stat(f, false);
} catch (NativeException e) {
throw new UncheckedIOException("Could not stat file " + f.getAbsolutePath(), e);
}
AccessType accessType = AccessType.viaSymlink(stat.getType() == FileInfo.Type.Symlink);
if (accessType == AccessType.VIA_SYMLINK) {
try {
stat = files.stat(f, true);
} catch (NativeException e) {
// For a symlink cycle, file.exists() returns false when unable to stat the file.
if (!f.exists()) {
return DefaultFileMetadata.missing(accessType);
}
throw new UncheckedIOException("Could not stat file " + f.getAbsolutePath(), e);
}
}
switch(stat.getType()) {
case File:
return DefaultFileMetadata.file(stat.getLastModifiedTime(), stat.getSize(), accessType);
case Directory:
return DefaultFileMetadata.directory(accessType);
case Missing:
return DefaultFileMetadata.missing(accessType);
case Other:
throw new UncheckedIOException("Unsupported file type for " + f.getAbsolutePath());
default:
throw new IllegalArgumentException("Unrecognised file type: " + stat.getType());
}
}
use of org.gradle.internal.file.FileMetadata.AccessType in project gradle by gradle.
the class NioFileMetadataAccessor method stat.
@Override
public FileMetadata stat(File file) {
Path path = file.toPath();
BasicFileAttributes attributes;
try {
attributes = Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
} catch (IOException e) {
return DefaultFileMetadata.missing(AccessType.DIRECT);
}
AccessType accessType = AccessType.viaSymlink(attributes.isSymbolicLink());
if (accessType == AccessType.VIA_SYMLINK) {
try {
attributes = Files.readAttributes(path, BasicFileAttributes.class);
} catch (IOException e) {
return DefaultFileMetadata.missing(AccessType.VIA_SYMLINK);
}
}
if (attributes.isDirectory()) {
return DefaultFileMetadata.directory(accessType);
}
if (attributes.isOther()) {
throw new UncheckedIOException("Unsupported file type for " + file.getAbsolutePath());
}
return DefaultFileMetadata.file(attributes.lastModifiedTime().toMillis(), attributes.size(), accessType);
}
Aggregations