Skip to content

Commit a70606c

Browse files
authored
Disable filesystem timestamp resolution persistence to JGit config (#9)
When user.home resolves to a relative or invalid path (e.g. "?" on JDK 8-18 in containers without a /etc/passwd entry for the running UID), FileStoreAttributes.saveToConfig() creates a config file inside the working directory. This pollutes the repository working tree, and the file ends up in the LST manifest. On Windows, the "?" character is illegal in paths, causing InvalidPathException when processing the LST. The in-memory FileStoreAttributes cache is sufficient for the lifetime of a JVM process. The only cost of not persisting is re-measuring filesystem timestamp resolution on the next JVM start, which is fast.
1 parent 3197067 commit a70606c

1 file changed

Lines changed: 5 additions & 61 deletions

File tree

  • jgit/src/main/java/org/openrewrite/jgit/util

jgit/src/main/java/org/openrewrite/jgit/util/FS.java

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -712,67 +712,11 @@ private static Optional<FileStoreAttributes> readFromConfig(
712712

713713
private static void saveToConfig(FileStore s,
714714
FileStoreAttributes c) {
715-
StoredConfig jgitConfig;
716-
try {
717-
jgitConfig = SystemReader.getInstance().getJGitConfig();
718-
} catch (IOException | ConfigInvalidException e) {
719-
LOG.error(JGitText.get().saveFileStoreAttributesFailed, e);
720-
return;
721-
}
722-
long resolution = c.getFsTimestampResolution().toNanos();
723-
TimeUnit resolutionUnit = getUnit(resolution);
724-
long resolutionValue = resolutionUnit.convert(resolution,
725-
TimeUnit.NANOSECONDS);
726-
727-
long minRacyThreshold = c.getMinimalRacyInterval().toNanos();
728-
TimeUnit minRacyThresholdUnit = getUnit(minRacyThreshold);
729-
long minRacyThresholdValue = minRacyThresholdUnit
730-
.convert(minRacyThreshold, TimeUnit.NANOSECONDS);
731-
732-
final int max_retries = 5;
733-
int retries = 0;
734-
boolean succeeded = false;
735-
String key = getConfigKey(s);
736-
while (!succeeded && retries < max_retries) {
737-
try {
738-
jgitConfig.setString(
739-
ConfigConstants.CONFIG_FILESYSTEM_SECTION, key,
740-
ConfigConstants.CONFIG_KEY_TIMESTAMP_RESOLUTION,
741-
String.format("%d %s", //$NON-NLS-1$
742-
Long.valueOf(resolutionValue),
743-
resolutionUnit.name().toLowerCase()));
744-
jgitConfig.setString(
745-
ConfigConstants.CONFIG_FILESYSTEM_SECTION, key,
746-
ConfigConstants.CONFIG_KEY_MIN_RACY_THRESHOLD,
747-
String.format("%d %s", //$NON-NLS-1$
748-
Long.valueOf(minRacyThresholdValue),
749-
minRacyThresholdUnit.name().toLowerCase()));
750-
jgitConfig.save();
751-
succeeded = true;
752-
} catch (LockFailedException e) {
753-
// race with another thread, wait a bit and try again
754-
try {
755-
retries++;
756-
if (retries < max_retries) {
757-
Thread.sleep(100);
758-
LOG.debug("locking {} failed, retries {}/{}", //$NON-NLS-1$
759-
jgitConfig, Integer.valueOf(retries),
760-
Integer.valueOf(max_retries));
761-
} else {
762-
LOG.warn(MessageFormat.format(
763-
JGitText.get().lockFailedRetry, jgitConfig,
764-
Integer.valueOf(retries)));
765-
}
766-
} catch (InterruptedException e1) {
767-
Thread.currentThread().interrupt();
768-
break;
769-
}
770-
} catch (IOException e) {
771-
LOG.error(MessageFormat.format(
772-
JGitText.get().cannotSaveConfig, jgitConfig), e);
773-
break;
774-
}
775-
}
715+
// Don't persist filesystem timestamp resolution to the JGit config
716+
// file. When user.home resolves to a relative or invalid path (e.g.
717+
// "?" on JDK 8-18 in containers), this creates files inside the
718+
// working tree that pollute the repository. The in-memory cache is
719+
// sufficient; the only cost is re-measuring on the next JVM start.
776720
}
777721

778722
private static String getConfigKey(FileStore s) {

0 commit comments

Comments
 (0)