|
From: vampire0 <vam...@us...> - 2025-03-31 13:14:44
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "jEdit core".
The branch, master has been updated
via 70840836eb6a3dffa42ef2fea7091f5cc8e5b922 (commit)
from a9885bb3c58a0fcd31cd608f501dbfe4d33e5c4a (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit: https://sourceforge.net/p/jedit/jEdit/ci/70840836eb6a3dffa42ef2fea7091f5cc8e5b922/
tree: https://sourceforge.net/p/jedit/jEdit/ci/70840836eb6a3dffa42ef2fea7091f5cc8e5b922/tree/
commit 70840836eb6a3dffa42ef2fea7091f5cc8e5b922
Author: Björn Kautler <Bj...@Ka...>
Date: Mon Mar 31 15:14:06 2025 +0200
Prevent multiple jEdit instances using the same settings directory using a file lock
diff --git a/doc/CHANGES.txt b/doc/CHANGES.txt
index d89f09e16..96f2dcacf 100644
--- a/doc/CHANGES.txt
+++ b/doc/CHANGES.txt
@@ -53,6 +53,9 @@ for contributing to this release.
- Do not check edit mode rules twice for hash chars that do not have upper- and
lowercase versions (Björn Kautler)
+- Prevent multiple jEdit instances using the same settings directory using a
+ file lock (Björn Kautler)
+
}}}
{{{ API Changes
diff --git a/org/gjt/sp/jedit/Buffer.java b/org/gjt/sp/jedit/Buffer.java
index 27f3d21e1..9a0899028 100644
--- a/org/gjt/sp/jedit/Buffer.java
+++ b/org/gjt/sp/jedit/Buffer.java
@@ -203,7 +203,7 @@ public class Buffer extends JEditBuffer
{
if(isPerformingIO())
{
- GUIUtilities.error(view,"buffer-multiple-io",null);
+ GUIUtilities.error(view,"buffer-multiple-io",(Object[])null);
return false;
}
@@ -344,7 +344,7 @@ public class Buffer extends JEditBuffer
{
if(isPerformingIO())
{
- GUIUtilities.error(view,"buffer-multiple-io",null);
+ GUIUtilities.error(view,"buffer-multiple-io",(Object[])null);
return false;
}
@@ -489,7 +489,7 @@ public class Buffer extends JEditBuffer
{
if(isPerformingIO())
{
- GUIUtilities.error(view,"buffer-multiple-io",null);
+ GUIUtilities.error(view,"buffer-multiple-io",(Object[])null);
return false;
}
diff --git a/org/gjt/sp/jedit/GUIUtilities.java b/org/gjt/sp/jedit/GUIUtilities.java
index 31256248e..432aee4ce 100644
--- a/org/gjt/sp/jedit/GUIUtilities.java
+++ b/org/gjt/sp/jedit/GUIUtilities.java
@@ -72,6 +72,8 @@ import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
+
+import static javax.swing.JOptionPane.ERROR_MESSAGE;
//}}}
/** Various GUI utility functions related to icons, menus, toolbars, keyboard shortcuts, etc.
@@ -671,27 +673,31 @@ public class GUIUtilities
* message text
*/
public static void error(final Component comp, final String name, final Object[] args)
+ {
+ error(comp,
+ jEdit.getProperty(name.concat(".title"),args),
+ jEdit.getProperty(name.concat(".message"),args));
+ }
+
+ /* package-private */ static void error(final Component comp, final String title, final String message)
{
if (EventQueue.isDispatchThread())
{
hideSplashScreen();
- JOptionPane.showMessageDialog(comp,
- jEdit.getProperty(name.concat(".message"),args),
- jEdit.getProperty(name.concat(".title"),args),
- JOptionPane.ERROR_MESSAGE);
+ JOptionPane.showMessageDialog(comp, message, title, ERROR_MESSAGE);
+ }
+ else
+ {
+ try
+ {
+ EventQueue.invokeAndWait(() -> error(comp, title, message));
+ }
+ catch (Exception e) // NOPMD
+ {
+ // ignored
+ }
}
- else
- {
- try
- {
- EventQueue.invokeAndWait(() -> error(comp, name, args));
- }
- catch (Exception e) // NOPMD
- {
- // ignored
- }
- }
} //}}}
//{{{ input() method
diff --git a/org/gjt/sp/jedit/Macros.java b/org/gjt/sp/jedit/Macros.java
index 6925a99ef..e198bdfde 100644
--- a/org/gjt/sp/jedit/Macros.java
+++ b/org/gjt/sp/jedit/Macros.java
@@ -649,7 +649,7 @@ public class Macros
Recorder recorder = view.getMacroRecorder();
if(recorder == null)
- GUIUtilities.error(view,"macro-not-recording",null);
+ GUIUtilities.error(view,"macro-not-recording",(Object[])null);
else
{
view.setMacroRecorder(null);
@@ -671,7 +671,7 @@ public class Macros
if(settings == null)
{
- GUIUtilities.error(view,"no-settings",null);
+ GUIUtilities.error(view,"no-settings",(Object[])null);
return;
}
@@ -681,7 +681,7 @@ public class Macros
if(jEdit.getBufferManager().getBuffer(path).isEmpty())
{
- GUIUtilities.error(view,"no-temp-macro",null);
+ GUIUtilities.error(view,"no-temp-macro",(Object[])null);
return;
}
diff --git a/org/gjt/sp/jedit/jEdit.java b/org/gjt/sp/jedit/jEdit.java
index 36722f7cb..7c2c8ea0a 100644
--- a/org/gjt/sp/jedit/jEdit.java
+++ b/org/gjt/sp/jedit/jEdit.java
@@ -46,6 +46,8 @@ import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -79,6 +81,8 @@ import org.gjt.sp.jedit.bufferset.BufferSetManager;
import org.gjt.sp.jedit.bufferset.BufferSet;
import static java.lang.Integer.parseInt;
+import static java.nio.file.StandardOpenOption.CREATE;
+import static java.nio.file.StandardOpenOption.WRITE;
//}}}
/**
@@ -398,10 +402,17 @@ public class jEdit
System.exit(0);
} //}}}
+ //{{{ Lock settings directory if it exists already
+ if ((settingsDirectory != null) &&
+ new File(settingsDirectory).isDirectory() &&
+ !lockSettingsDirectory())
+ return;
+ // }}}
+
// don't show splash screen if there is a file named
// 'nosplash' in the settings directory
logTime("before splash screen activation");
- if(splash && (!new File(settingsDirectory,"nosplash").exists()))
+ if(splash && ((settingsDirectory == null) || !new File(settingsDirectory, "nosplash").exists()))
GUIUtilities.showSplashScreen();
logTime("after splash screen activation");
//{{{ Settings migration code.
@@ -418,9 +429,16 @@ public class jEdit
Writer stream;
if(settingsDirectory != null)
{
- File _settingsDirectory = new File(settingsDirectory);
- if(!_settingsDirectory.exists())
- _settingsDirectory.mkdirs();
+ if(settingsLock == null)
+ {
+ File _settingsDirectory = new File(settingsDirectory);
+ if(!_settingsDirectory.exists())
+ _settingsDirectory.mkdirs();
+
+ // Lock settings directory if it was newly created or relocated
+ if (!lockSettingsDirectory()) return;
+ }
+
File _macrosDirectory = new File(settingsDirectory,"macros");
if(!_macrosDirectory.exists())
_macrosDirectory.mkdir();
@@ -651,6 +669,40 @@ public class jEdit
logTime("main done");
} //}}}
+ //{{{ lockSettingsDirectory() method
+ private static boolean lockSettingsDirectory()
+ {
+ try
+ {
+ String settingsLockFileName = ".lock";
+ File settingsLockFile = new File(settingsDirectory, settingsLockFileName);
+ settingsLock = FileChannel.open(settingsLockFile.toPath(), CREATE, WRITE).tryLock();
+ System.err.println("Settings directory lock acquired: " + settingsLock);
+
+ if(settingsLock == null)
+ {
+ // Localization properties are not yet initialized, so we use a hard-coded message here
+ String errorMessage = "The settings directory " +
+ new File(settingsDirectory).getAbsolutePath() +
+ " is locked by another jEdit instance.\n" +
+ "If you are sure there is no other jEdit instance running," +
+ " delete the file named \"" + settingsLockFileName + "\".";
+ GUIUtilities.error(null,"Settings Directory is locked",errorMessage);
+ return false;
+ }
+ else
+ {
+ settingsLockFile.deleteOnExit();
+ }
+ }
+ catch(Exception e)
+ {
+ Log.log(Log.ERROR, jEdit.class, "Error while trying to lock settings directory", e);
+ System.exit(1);
+ }
+ return true;
+ } //}}}
+
//{{{ Property methods
//{{{ getCurrentLanguage() method
@@ -3262,6 +3314,7 @@ public class jEdit
//{{{ Static variables
private static String jEditHome;
private static String settingsDirectory;
+ private static FileLock settingsLock;
private static String jarCacheDirectory;
private static long propsModTime;
private static PropertyManager propMgr = new PropertyManager();
-----------------------------------------------------------------------
Summary of changes:
doc/CHANGES.txt | 3 ++
org/gjt/sp/jedit/Buffer.java | 6 ++--
org/gjt/sp/jedit/GUIUtilities.java | 36 ++++++++++++----------
org/gjt/sp/jedit/Macros.java | 6 ++--
org/gjt/sp/jedit/jEdit.java | 61 +++++++++++++++++++++++++++++++++++---
5 files changed, 87 insertions(+), 25 deletions(-)
hooks/post-receive
--
jEdit core
|