You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "lahodaj (via GitHub)" <gi...@apache.org> on 2023/10/30 21:11:27 UTC

[PR] [NETBEANS-4962] Adding ability to disable hard-locking files using lock files. [netbeans]

lahodaj opened a new pull request, #6639:
URL: https://github.com/apache/netbeans/pull/6639

   NetBeans FileSystems have a notion of file locking. And, when two (or more) files with the same name, but different paths, are locked, there are lock file written next to the files on the OS file system. Investigating this, it seems the reason is to detect multiple lock for the same "real" file available under multiple paths. That may happen e.g. by using symbolic links, `mount --bind` or network files. Materializing the lock files on the OS file system should allow to detect multiple lock attempts for the same "real" file.
   
   Not sure how important this is, but I don't recall any complaints about this while running a NB platform app or NB-based IDE, so keeping the behavior for these usecases would make sense to me. Note the NB FileSystems don't model the lock files at all, so they are invisible when using the NB FS, and hence mostly invisible inside the IDE.
   
   But, in the context of an VS Code extension, the lock files are problematic. It is fairly easy to produce them, and they are visible to the user. So, preferably, the lock files should not be created in the extension(s). Please see:
   https://issues.apache.org/jira/browse/NETBEANS-5402
   
   So, my proposal herein is to abstract the hard-lock creation, and create either the lock files, or keep hard-locks in memory only. Where NB would use the former, and the VS Code extension(s) the latter.
   
   This means the VS Code extension(s) won't be able to detect some double-locking of the same file using different paths, but I think that is OK/acceptable. I've used `Path.toRealPath()`, so symbolic links are resolved, and hence double-locking across sym-linked directories should still work. We'll see how that goes, if this proves to be too resource intensive, we might need to drop that. Double-locking a file that is mounted multiple times won't be detected.
   
   For the record, I am not a real expert on NB FS, and so this patch is fairly dangerous. It may need some baking time on master, at least for NB IDE.
   
   ---
   **^Add meaningful description above**
   
   By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
   
    - are all your own work, and you have the right to contribute them.
    - are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).
   
   Please make sure (eg. `git log`) that all commits have a valid name and email address for you in the Author field.
   
   If you're a first time contributor, see the Contributing guidelines for more information.
   
   If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] [NETBEANS-4962] Adding ability to disable hard-locking files using lock files. [netbeans]

Posted by "jtulach (via GitHub)" <gi...@apache.org>.
jtulach commented on code in PR #6639:
URL: https://github.com/apache/netbeans/pull/6639#discussion_r4102899572


##########
java/java.lsp.server/nbcode/integration/src/META-INF/services/org.netbeans.modules.masterfs.filebasedfs.fileobjects.LockForFile$HardLockRegistry:
##########
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+#suppress the file-based hard locks:
+#-org.netbeans.modules.masterfs.filebasedfs.fileobjects.LockForFile$FileBaseHardLockRegistry

Review Comment:
   I'd like the use-case to be described in `platform/masterfs/arch.xml` - e.g.
   ```
   <api group="lookup" type="export" name="Disable .LCK files" category="devel">
   To disable.... remove this class ... this is an API under development and may be replaced or changed in the future.
   </api>
   ```
   Also add **versioning** and a note into `apichanges.xml`.



##########
platform/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/LockForFile.java:
##########
@@ -292,12 +275,134 @@ private void hardLock() throws IOException {
                 if (reference != null) {
                     LockForFile lockForFile = reference.get();
                     if (lockForFile != null) {
-                        if (!FileChangedManager.getInstance().exists(lockForFile.getLock())) {
+                        if (!HardLockRegistry.getInstance().hardLockExists(lockForFile.getLock())) {
                             lockForFile.hardLock();
                         }
                     }
                 }
             }
         }
     }
+
+    public static boolean hasActiveLockFileSigns(final String filename) {
+        return filename.startsWith(PREFIX) && filename.endsWith(SUFFIX);
+    }
+
+    static final class HardLockPath {
+        public final File file;
+
+        public HardLockPath(File file) {
+            this.file = file;
+        }
+
+    }
+
+    /*not private for tests*/
+    public static interface HardLockRegistry {

Review Comment:
   - the name of the class is an API
      - one needs it to create appropriate `META-INF/services` file
   - **make the class top-level**, please!
   - I would even suggest to give it a dedicated package
      - maybe `org.netbeans.modules.masterfs.locking`?
   - **update the Javadoc** it seems out of date given the new use-case created by this PR



##########
platform/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/LockForFile.java:
##########
@@ -292,12 +275,134 @@ private void hardLock() throws IOException {
                 if (reference != null) {
                     LockForFile lockForFile = reference.get();
                     if (lockForFile != null) {
-                        if (!FileChangedManager.getInstance().exists(lockForFile.getLock())) {
+                        if (!HardLockRegistry.getInstance().hardLockExists(lockForFile.getLock())) {
                             lockForFile.hardLock();
                         }
                     }
                 }
             }
         }
     }
+
+    public static boolean hasActiveLockFileSigns(final String filename) {
+        return filename.startsWith(PREFIX) && filename.endsWith(SUFFIX);
+    }
+
+    static final class HardLockPath {
+        public final File file;
+
+        public HardLockPath(File file) {
+            this.file = file;
+        }
+
+    }
+
+    /*not private for tests*/
+    public static interface HardLockRegistry {
+        public static HardLockRegistry getInstance() {
+            return HardLockRegistryInstance.INSTANCE;
+        }
+
+        public void doHardLock(HardLockPath hardLock, String absolutePath) throws IOException;
+
+        public boolean doHardUnlock(HardLockPath hardLock);
+
+        public boolean hardLockExists(HardLockPath hardLock) throws IOException;
+
+        public String getHardLockContent(HardLockPath hardLock);
+
+    }
+
+    //init the HardLockRegistry instance lazily:
+    private static final class HardLockRegistryInstance {
+        public static final HardLockRegistry INSTANCE = Lookup.getDefault().lookup(HardLockRegistry.class);
+    }
+
+    @ServiceProvider(service=HardLockRegistry.class, position=100)
+    public static final class FileBaseHardLockRegistry implements HardLockRegistry {

Review Comment:
   - Make it a top level class, maybe? 
   - The name of the class becomes an API ... 
   - avoiding `$` in the name ... simplifies the API



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] [NETBEANS-4962] Adding ability to disable hard-locking files using lock files. [netbeans]

Posted by "lahodaj (via GitHub)" <gi...@apache.org>.
lahodaj commented on PR #6639:
URL: https://github.com/apache/netbeans/pull/6639#issuecomment-6271160003

   I have rebased to the current master, and reflected the review comments. I didn't introduce a new package, as there are package-private reference to and from `LockForFile`, which would need to be upgraded for `public`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] [NETBEANS-4962] Adding ability to disable hard-locking files using lock files. [netbeans]

Posted by "jtulach (via GitHub)" <gi...@apache.org>.
jtulach commented on code in PR #6639:
URL: https://github.com/apache/netbeans/pull/6639#discussion_r4344545910


##########
platform/masterfs/src/org/netbeans/modules/masterfs/filebasedfs/fileobjects/HardLockRegistry.java:
##########
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.masterfs.filebasedfs.fileobjects;
+
+import java.io.File;
+import java.io.IOException;
+import org.openide.util.Lookup;
+
+/** A pluggable hard lock handler. */

Review Comment:
   Add a link to https://github.com/apache/netbeans/pull/6639/changes#r4344525386 - e.g. something like:
   
   ```html
   <a href="@TOP@/architecture-summary.html#disable-.lck-files">
   ```
   



##########
platform/masterfs/apichanges.xml:
##########
@@ -19,12 +19,24 @@
     under the License.
 
 -->
-<!DOCTYPE apichanges PUBLIC "-//NetBeans//DTD API changes list 1.0//EN" "../../nbbuild/javadoctools/apichanges.dtd">
+<!DOCTYPE apichanges PUBLIC "-//NetBeans//DTD API changes list 1.1//EN" "../../nbbuild/javadoctools/apichanges-1.1.dtd">
 <apichanges>
     <apidefs>
         <apidef name="masterfs">MasterFileSystem API</apidef>
     </apidefs>
     <changes>
+        <change id="disable.hard.locks">
+            <api name="masterfs"/>
+            <summary>Split image handling into UI module</summary>

Review Comment:
   "Split image handling into UI  module?" - probably copy and paste error. Try to generate `ant javadoc` and then read thru the generated pages.



##########
platform/masterfs/arch.xml:
##########
@@ -112,6 +112,13 @@ cases. FileObjects erlier returned from <code>URLMapper</code> or
 <code>CvsFileSystem</code> will be now provided by <code>MasterFileSystem</code>. 
 There will be guaranteed that there won't be more instances of FileObject 
 addressing one <code>java.ioFile</code>.
+<api name="Disable .LCK files" group="lookup" type="export" category="devel">

Review Comment:
   Short, but exactly to the point. Thanks. This entry generates a stable `<a name` reference. I suggest to link to it from various places.



##########
platform/masterfs/apichanges.xml:
##########
@@ -19,12 +19,24 @@
     under the License.
 
 -->
-<!DOCTYPE apichanges PUBLIC "-//NetBeans//DTD API changes list 1.0//EN" "../../nbbuild/javadoctools/apichanges.dtd">
+<!DOCTYPE apichanges PUBLIC "-//NetBeans//DTD API changes list 1.1//EN" "../../nbbuild/javadoctools/apichanges-1.1.dtd">
 <apichanges>
     <apidefs>
         <apidef name="masterfs">MasterFileSystem API</apidef>
     </apidefs>
     <changes>
+        <change id="disable.hard.locks">
+            <api name="masterfs"/>
+            <summary>Split image handling into UI module</summary>
+            <version major="2" minor="91"/>
+            <date day="26" month="10" year="2026"/>
+            <author login="jlahoda"/>
+            <compatibility binary="compatible" source="compatible" deletion="no"/>
+            <description>
+                Adding an ability to disable hard-locks using files on the file system.

Review Comment:
   Add a link to the "a name" reference to https://github.com/apache/netbeans/pull/6639/changes#r4344525386 - it would be something like:
   
   ```html
   <a href="@TOP@/architecture-summary.html#disable-.lck-files">
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


Re: [PR] [NETBEANS-4962] Adding ability to disable hard-locking files using lock files. [netbeans]

Posted by "neilcsmith-net (via GitHub)" <gi...@apache.org>.
neilcsmith-net commented on PR #6639:
URL: https://github.com/apache/netbeans/pull/6639#issuecomment-1891795404

   > For the record, I am not a real expert on NB FS, and so this patch is fairly dangerous. It may need some baking time on master, at least for NB IDE.
   
   This makes me inclined to bump the milestone early! :smile:


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists