From d66175d7dca30be7ab96af0e3998f795a174b891 Mon Sep 17 00:00:00 2001 From: Kaushik Lingarkar Date: Tue, 20 Aug 2024 15:50:20 -0700 Subject: LockFile: Retry lock creation if parent dirs were removed In the small window between creation of the lock file's parent dirs and the lock file itself, the parent dirs may be cleaned by an external process packing refs in the repository. When this scenario occurs, retry creating the lock file (along with its parent dirs). Change-Id: Id7ec60c3f7f373b59f1dc8de6b8fa6df6bdf2570 Signed-off-by: Kaushik Lingarkar --- .../eclipse/jgit/internal/storage/file/LockFile.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java index a2d8bd0140..1983541e4a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java @@ -24,6 +24,7 @@ import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.FileChannel; import java.nio.file.Files; +import java.nio.file.NoSuchFileException; import java.nio.file.StandardCopyOption; import java.nio.file.attribute.FileTime; import java.text.MessageFormat; @@ -141,9 +142,8 @@ public class LockFile { throw new IllegalStateException( MessageFormat.format(JGitText.get().lockAlreadyHeld, ref)); } - FileUtils.mkdirs(lck.getParentFile(), true); try { - token = FS.DETECTED.createNewFileAtomic(lck); + token = createLockFileWithRetry(); } catch (IOException e) { LOG.error(JGitText.get().failedCreateLockFile, lck, e); throw e; @@ -160,6 +160,19 @@ public class LockFile { return obtainedLock; } + private FS.LockToken createLockFileWithRetry() throws IOException { + try { + return createLockFile(); + } catch (NoSuchFileException e) { + return createLockFile(); + } + } + + private FS.LockToken createLockFile() throws IOException { + FileUtils.mkdirs(lck.getParentFile(), true); + return FS.DETECTED.createNewFileAtomic(lck); + } + /** * Try to establish the lock for appending. * -- cgit v1.2.3 From 692ccfc0c29d53afc7a0b82f41efcd999ed217b0 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Tue, 27 Aug 2024 01:31:44 +0200 Subject: AmazonS3: Ensure SAXParserFactory sets valid/expected input params Change Ie8a9d411fc19e8b7bf86c0b4df0b02153a0e9444 broke setting valid/expected input parameters for the XML parser. This can be fixed by calling SaxParserFactory#setNamespaceAware, see [1]. Also see earlier fix in [2]. [1] https://stackoverflow.com/questions/24891323/namespace-handling-with-sax-in-java [2] I05e993032ab3a6afb78634290b578ebc73cf1cbd Bug: jgit-87 Change-Id: Id4e9eebac8d9de81e5d48a608066db3cc862e15c --- org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java index b873925316..aaf9f8a08a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AmazonS3.java @@ -757,8 +757,10 @@ public class AmazonS3 { final XMLReader xr; try { - xr = SAXParserFactory.newInstance().newSAXParser() - .getXMLReader(); + SAXParserFactory saxParserFactory = SAXParserFactory + .newInstance(); + saxParserFactory.setNamespaceAware(true); + xr = saxParserFactory.newSAXParser().getXMLReader(); } catch (SAXException | ParserConfigurationException e) { throw new IOException( JGitText.get().noXMLParserAvailable, e); -- cgit v1.2.3