use of net.rubygrapefruit.platform.file.FileInfo 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());
}
}
Aggregations