Check whether underlying file system supports file locking.

@return <code>true</code> if exclusive locks are supported or
<code>false</code> otherwise.
@throws IOException
@see StorageDirectory#lock()
764097
public boolean isLockSupported(int idx) throws IOException {
    StorageDirectory sd = storageDirs.get(idx);
    FileLock firstLock = null;
    FileLock secondLock = null;
    try {
      firstLock = sd.lock;
      if(firstLock == null) {
        firstLock = sd.tryLock();
        if(firstLock == null)
          return true;
      }
      secondLock = sd.tryLock();
      if(secondLock == null)
        return true;
    } finally {
      if(firstLock != null && firstLock != sd.lock) {
        firstLock.release();
        firstLock.channel().close();
      }
      if(secondLock != null) {
        secondLock.release();
        secondLock.channel().close();
      }
    }
    return false;
  }
1215812
boolean isLocked(Path lockFile) throws JobLockException {
    try {
      return this.fs.exists(lockFile);
    } catch (IOException e) {
      throw new JobLockException(e);
    }
  }
626489
private boolean refill() throws IOException {
    if (!byteBuffer.hasRemaining()) {
      byteBuffer.clear();
      int nRead = 0;
      while (nRead == 0) {
        nRead = fileChannel.read(byteBuffer);
      }
      if (nRead < 0) {
        return false;
      }
      byteBuffer.flip();
    }
    return true;
  }
846574
public final FileLock lock(final int tryLockMax, final long tryWaitMillis) throws LockingFailedException {

        return Utils4J.lockRandomAccessFile(file, tryLockMax, tryWaitMillis);

    }
457850
public function lock()
    {
        if ($this->isRunning())
            return false;

        $pidFile = $this->directory.$this->filename;

        if (!is_writable($this->directory)) {
            throw new \Exception('Can not write to folder: '.$this->directory);
        }

        if (file_exists($pidFile) && !is_writable($pidFile)) {
            throw new \Exception('Can not write to file: '.$pidFile);
        }

        $file = fopen($pidFile, 'w');
        if ($file === false) {
            return false;
        }

        fputs($file, getmypid());
        fclose($file);

        return true;
    }
547629
private FileSystem getFileSystemSafe() throws IOException
    {
        try {
            fs.getFileStatus(new Path("/"));
            return fs;
        }
        catch (NullPointerException e) {
            throw new IOException("file system not initialized");
        }
    }
1306578
public void unlock() throws IOException {
    if (fileLock != null) {
      try {
        fileLock.release();
      } catch (ClosedChannelException e) {
      }
      fileLock = null;
    }
  }
810428
@Override
    public void checkRepositoryStatus() throws IOException {
        if (!DirectoryUtils.exists(_zip)) {
            throw new FileNotFoundException("Could not find " + _zip);
        }
        // This will throw an exception if the file is not a zip
        ZipFile zip = DirectoryUtils.createZipFile(_zip);
        // if the creation of the zip file is successful ensure it is closed to release the lock
        zip.close();
    }
873968
@VisibleForTesting
  /* package protected */ synchronized DiskStorage get() throws IOException {
    if (shouldCreateNewStorage()) {
      // discard anything we created
      deleteOldStorageIfNecessary();
      createStorage();
    }
    return Preconditions.checkNotNull(mCurrentState.delegate);
  }
1015403
@Override
    public FileLock tryLock(long position, long size, boolean shared) throws IOException
    {
        return new FileLockImpl(this, position, size, shared);
    }
22844
private boolean tryLockExclusive()
  {
    if (tc.isEntryEnabled())
      SibTr.entry(tc, "tryLockExclusive", this);

    boolean result = false;

    // Synchronize on the locking Mutex
    synchronized (iMutex)
    {
      // If it isn't already locked - lock it on this thread.
      if (!iExclusivelyLocked)
      {
        // Block new many lock requests
        iExclusivelyLocked = true;

        // Set the exclusive lock holder to be this thread
        iExclusiveLockHolder = Thread.currentThread();

        if (tc.isDebugEnabled())
          SibTr.debug(tc, "Got exclusive lock for thread " + iExclusiveLockHolder);

        // Set the return result to be true
        result = true;
        
        // Increment the exclusive lock count
        iExclusiveLockCount++;
      }
      // If we are locked, then check that the thread that is requesting
      // this lock is the same thread that owns the lock already.
      else if (iExclusiveLockHolder == Thread.currentThread())
      {
        if (tc.isDebugEnabled())
          SibTr.debug(tc, "Already hold exclusive lock " + (iExclusiveLockCount + 1));
        result = true;
        // Increment the exclusive lock count
        iExclusiveLockCount++;
        
      }
    }

    if (tc.isEntryEnabled())
      SibTr.exit(tc, "tryLockExclusive", new Boolean(result));

    return result;
  }
1232108
public function isLink()
    {
        clearstatcache();
        $fs = FileSystem::getFileSystem();
        if ($fs->checkAccess($this) !== true) {
            throw new IOException("No read access to " . $this->path);
        }

        return @is_link($this->path);
    }
84309
def contains_locked_file(directory: str):
    
    for root, subdirs, files in os.walk(directory):
        for filename in files:
            file_path = os.path.join(root, filename)
            try:
                with open(file_path, 'a'):
                    pass
            except IOError:
                logger.debug(f"Locked file: {file_path}")
                return True
    return False
422583
@Override
    public boolean isLocked()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "isLocked");

        final boolean isLocked = (state == SIMPState.LOCKED);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "isLocked", Boolean.valueOf(isLocked));

        return isLocked;
    }
914052
private ReentrantReadWriteLock getFileLock(String jspVfsName) {

        ReentrantReadWriteLock lock = m_fileLocks.get(jspVfsName);
        if (lock == null) {
            // acquire the purge lock before adding new file lock entries
            // in case of a JSP repository purge, adding new file lock entries is blocked
            // and all present file locks will be locked for purge
            // @see #triggerPurge()
            m_purgeLock.readLock().lock();
            synchronized (m_fileLocks) {
                if (!m_fileLocks.containsKey(jspVfsName)) {
                    m_fileLocks.put(jspVfsName, new ReentrantReadWriteLock(true));
                }
                lock = m_fileLocks.get(jspVfsName);
            }
            m_purgeLock.readLock().unlock();
        }
        return lock;
    }
472833
private boolean processLockingMechanism() throws JournalException {
        boolean locked;
        if (lockRequestedFile.exists()) {
            try {
                if (!lockAcceptedFile.exists()) {
                    lockAcceptedFile.createNewFile();
                }
            } catch (IOException e) {
                throw new JournalException("Unable to create 'Lock Accepted' file at '"
                        + lockAcceptedFile.getPath() + "'");
            }
            locked = true;
        } else {
            if (lockAcceptedFile.exists()) {
                lockAcceptedFile.delete();
            }
            locked = false;
        }

        if (locked && !wasLocked) {
            recoveryLog.log("Lock request detected: "
                    + lockRequestedFile.getPath() + ", Lock accepted: "
                    + lockAcceptedFile.getPath());
        } else if (wasLocked && !locked) {
            recoveryLog.log("Lock request removed: "
                    + lockRequestedFile.getPath());
        }

        wasLocked = locked;
        return locked;
    }
393816
@Override public boolean isReleasable() {
    int r = _rwlock.get();
    if( _key.home() ) {         // Called from lock_and_invalidate
      // Home-key blocking: wait for active-GET count to fall to zero, or blocking on deleted object
      return r <= 0;
    } else {                    // Called from start_put
      // Remote-key blocking: wait for active-PUT lock to hit -1
      assert r == 2 || r == -1; // Either waiting (2) or done (-1) but not started(1)
      return r == -1;           // done!
    }
  }