Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions gortools/src/main/java/gorsat/process/GorJavaUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,12 +579,9 @@ public static String verifyLinkFileLastModified(ProjectContext projectContext, S

public static void writeDictionaryFromMeta(FileReader fileReader, String outfolderpath, String dictionarypath) throws IOException {
FileReader localFileReader = fileReader;
if (PathUtils.isLocal(outfolderpath)) {
// Force meta data update on the parent (solves issue with NFS sycn)
try (Stream<String> paths = fileReader.list(PathUtils.getParent(outfolderpath))) {
// Intentionally empty.
}
}

fileReader.updateFileSystemMetaData(outfolderpath);

try (Stream<String> metapathstream = localFileReader.list(outfolderpath);
Writer dictionarypathwriter = new OutputStreamWriter(localFileReader.getOutputStream(dictionarypath))) {
var metaList = metapathstream.parallel().filter(p -> DataUtil.isMeta(p)).map(p -> GorMeta.createAndLoad(localFileReader, p)).collect(Collectors.toList());
Expand Down
2 changes: 1 addition & 1 deletion gortools/src/main/scala/gorsat/InputSources/Gorif.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Gorif extends InputSourceInfo("GORIF",
// Filter out filepath if not exists
val nonExistentFiles = iargs.filter(arg =>
!CommandParseUtilities.isNestedCommand(arg) &&
!context.getSession.getProjectContext.getFileReader.exists(arg)).toList
!context.getSession.getProjectContext.getFileReader.existsWithMetaDataUpdate(arg)).toList
val checkedIargs = iargs.filterNot(nonExistentFiles.contains)

if (checkedIargs.isEmpty) {
Expand Down
2 changes: 1 addition & 1 deletion gortools/src/main/scala/gorsat/InputSources/Nor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ object Nor
// Filter out filepath if not exists
val nonExistentFiles = iargs.filter(arg =>
!CommandParseUtilities.isNestedCommand(arg) &&
!context.getSession.getProjectContext.getFileReader.exists(arg)).toList
!context.getSession.getProjectContext.getFileReader.existsWithMetaDataUpdate(arg)).toList
val checkedIargs = iargs.filterNot(nonExistentFiles.contains)

if (checkedIargs.isEmpty) {
Expand Down
39 changes: 39 additions & 0 deletions model/src/main/java/org/gorpipe/gor/model/FileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.gorpipe.gor.driver.meta.SourceReference;
import org.gorpipe.gor.driver.providers.stream.sources.StreamSource;
import org.gorpipe.gor.driver.utils.LinkFile;
import org.gorpipe.gor.table.util.PathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -363,4 +364,42 @@ public FileReader unsecure() {
public Stream<SourceRef> prepareSources(Stream<SourceRef> sources) {
return sources;
}

/**
* Update the file system metadata for the given path/file.
* NOTE: This can be expensive, so it should be used with care. This is only needed for
* (shared)filesystems (not object storage).
* @param path
* @throws IOException
*/
public void updateFileSystemMetaData(String path) throws IOException {
if (PathUtils.isLocal(path)) {
// Force meta data update on the parent (solves issue with NFS sycn)
try (Stream<String> paths = this.list(PathUtils.getParent(path))) {
// Intentionally empty.
}
}
}

/**
* Check if a file exists, and if not, update the file system metadata for the given path.
* This is useful when working with files that may have been recently created or modified.
*
* @param path The path to check for existence.
* @return true if the file exists, false otherwise.
*/
public boolean existsWithMetaDataUpdate(String path) {
if (exists(path)) {
return true;
} else {
try {
// If the file does not exist, we try to update the metadata.
updateFileSystemMetaData(path);
} catch (IOException e) {
log.warn("Could not update file system metadata for path: {}", path, e);
return false;
}
return exists(path);
}
}
}
Loading