Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JimFS doesn't handle file locks in documented way (OverlappingFileLockException) #67

Open
nick7ikin opened this issue Apr 12, 2018 · 0 comments
Labels

Comments

@nick7ikin
Copy link

If I try to lock regular file then locking it the second time will raise OverlappingFileLockException as described in FileChannel documentation

JimFS allows to lock the same file multiple times. Here is a test code

    public void testJimfsLock() throws IOException {

        FileSystem jimFs = Jimfs.newFileSystem();
        FileSystem fs = FileSystems.getDefault();

        checkLock(jimFs.getPath("/lockfile"));
        checkLock(fs.getPath("/tmp/lockfile"));

    }

    private void checkLock(Path lockFilePath) throws IOException {
        System.out.println("lockFilePath=" + lockFilePath);
        FileChannel fileChannel = FileChannel.open(lockFilePath, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
        FileLock lock1 = fileChannel.lock();
        FileLock lock2 = null;
        try {
            lock2 = fileChannel.tryLock();
        } catch (OverlappingFileLockException e) {
            System.out.println("got OverlappingFileLockException");
        }

        System.out.println("lock1=" + lock1);
        System.out.println("lock2=" + lock2);
    }

It will print the following output:

lockFilePath=/lockfile
lock1=com.google.common.jimfs.JimfsFileChannel$FakeFileLock[0:9223372036854775807 exclusive valid]
lock2=com.google.common.jimfs.JimfsFileChannel$FakeFileLock[0:9223372036854775807 exclusive valid]
lockFilePath=/tmp/lockfile
got OverlappingFileLockException
lock1=sun.nio.ch.FileLockImpl[0:9223372036854775807 exclusive valid]
lock2=null

As you see attempting to lock file for the second time on regular file system leads to OverlappingFileLockException.

@cpovirk cpovirk added the P3 label Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants