@param string $lockFile

@throws Exception
435990
public function releaseLock($lockFile)
    {
        if (!array_key_exists($lockFile, $this->lockHandles)) {
            throw new Exception("Lock NOT held - bug? Lockfile: $lockFile");
        }

        if ($this->lockHandles[$lockFile]) {
            ftruncate($this->lockHandles[$lockFile], 0);
            flock($this->lockHandles[$lockFile], LOCK_UN);
        }

        unset($this->lockHandles[$lockFile]);
    }
344831
private Path getFileForLockFile(Path lockFile, Path sourceDirPath)
          throws IOException {
    String lockFileName = lockFile.getName();
    Path dataFile = new Path(sourceDirPath + Path.SEPARATOR + lockFileName + inprogress_suffix);
    if( hdfs.exists(dataFile) ) {
      return dataFile;
    }
    dataFile = new Path(sourceDirPath + Path.SEPARATOR +  lockFileName);
    if(hdfs.exists(dataFile)) {
      return dataFile;
    }
    return null;
  }
1249117
protected function loadPackages(JsonFile $lockFile)
    {
        $lock = $lockFile->read();
        foreach ($this->managers as $name => $m) {
            $m->setConfig($lock[$name]);
        }
    }
1244008
protected function setLockDirectory($lockDirectory)
    {
        if (! is_dir($lockDirectory)) {
            throw new InvalidArgumentException(sprintf('"%s" is not a valid directory', $lockDirectory));
        }

        if (! is_writable($lockDirectory)) {
            throw new InvalidArgumentException(sprintf('"%s" is not a writable directory', $lockDirectory));
        }

        $this->lockDirectory = $lockDirectory;
    }
506238
public void release() throws Exception {
        synchronized (this) {
            if (log.isDebugEnabled()) {
                log.debug("Releasing lock on " + lockFile.getAbsolutePath());
            }
            if (fileLock != null) {
                try {
                    fileLock.release();
                    fileLock = null;
                } catch (Exception e) {
                    throw new Exception("Unable to release locked file: " + lockFile.getAbsolutePath(), e);
                }
                if (fileChannel != null) {
                    try {
                        fileChannel.close();
                    } catch (IOException e) {
                        // ignore
                    }
                    fileChannel = null;
                }
                if (lockFile != null) {
                    if (lockFile.exists()) {
                        lockFile.delete();
                    }
                    lockFile = null;
                }
            }
        }
    }
1294450
public function set_lockfile($name=null) {
		
		if(!is_null($name) && $this->lockFile === $name && $this->is_lockfile_present()) {
			//do nothing.
		}
		else {
			if($this->is_lockfile_present()) {
				throw new exception(__METHOD__ .": cannot change lockfile name (to '". $name ."') when file exists (". $this->lockFile .")");
			}
			elseif(is_null($name)) {
				$name = self::defaultLockfile;
			}

			$this->lockFile = $name;
			try {
				if(!strpos($name, '\\') && !strpos($name, '/')) { //preg_match('/\//', $name) && !preg_match('/\\/', $name)) {
					$this->get_rwdir();
					$this->lockFile = $name;
				}
				else {
					throw new exception(__METHOD__ .": name (". $name .") has invalid characters");
				}
			}
			catch(exception $e) {
				throw new exception(__METHOD__ .": error while setting lockfile::: ". $e->getMessage());
			}
		}
		
		return($this->lockFile);
	}
1064260
public function runMigration($file)
    {
        $migration = $this->getMigrationObjectByFileName($file);

        $this->disableBitrixIblockHelperCache();

        $this->checkTransactionAndRun($migration, function () use ($migration, $file) {
            if ($migration->up() === false) {
                throw new Exception("Migration up from {$file}.php returned false");
            }
        });

        $this->logSuccessfulMigration($file);
    }
404456
protected function copyFile($sourceFile, $destFile) {
        $status = copy($sourceFile, $destFile);

        if ($status === false) {
            throw new Exception(sprintf(
                'Unable to copy file "%s" to "%s"',
                $sourceFile,
                $destFile
            ), ExitApp::RUNTIME_ERROR);
        }

        return $this;
    }
1231398
protected function insertDocBlock(File $phpCsFile, int $docBlockStartPosition): void
    {
        $phpCsFile->fixer->addContent($docBlockStartPosition, '/**');
        $phpCsFile->fixer->addNewline($docBlockStartPosition);
        $phpCsFile->fixer->addContent($docBlockStartPosition, ' * ' . static::EXPLANATION_CONSTANTS_INTERFACE);
        $phpCsFile->fixer->addNewline($docBlockStartPosition);
        $phpCsFile->fixer->addContent($docBlockStartPosition, ' */');
    }
1157152
private static function _stopReadLockProcessing(Zend_Search_Lucene_Storage_Directory $lockDirectory)
    {
        $lock = $lockDirectory->getFileObject(self::READ_LOCK_PROCESSING_LOCK_FILE);
        $lock->unlock();
    }
643041
protected function configureLockDirectory(string $lockDirectory)
    {
        Utility\Files::createDirectoryRecursively($lockDirectory);
        $this->temporaryDirectory = $lockDirectory;
    }
1216770
public function checkSourceAutoload($autoloadFile)
    {
        if (false === $this->coverFishHelper->checkFileExist($autoloadFile)) {
            throw new \Exception(sprintf('autoload file "%s" not found! please define your autoload.php file to use (e.g. ../app/autoload.php in symfony)', $autoloadFile));
        }

        return true;
    }
767891
protected function checkBeginningOfDocBlock(File $phpCsFile, int $docBlockStartIndex, int $nextIndex): void
    {
        $tokens = $phpCsFile->getTokens();

        $diff = $tokens[$nextIndex]['line'] - $tokens[$docBlockStartIndex]['line'];
        if ($diff < 2) {
            return;
        }

        $fix = $phpCsFile->addFixableError('Expected no extra blank line before tags, got ' . ($diff - 1), $nextIndex, 'NoExtraNewlineBeforeTags');
        if ($fix) {
            return;
        }

        $phpCsFile->fixer->beginChangeset();

        for ($i = $docBlockStartIndex; $i < $nextIndex; $i++) {
            if ($tokens[$i]['line'] <= $tokens[$docBlockStartIndex]['line'] || $tokens[$i]['line'] >= $tokens[$nextIndex]['line']) {
                continue;
            }
            $phpCsFile->fixer->replaceToken($i, '');
        }

        $phpCsFile->fixer->endChangeset();
    }
1138841
protected function tryToAcquireLock(bool $exclusiveLock): bool
    {
        $this->filePointer = @fopen($this->lockFileName, 'w');
        if ($this->filePointer === false) {
            throw new LockNotAcquiredException(sprintf('Lock file "%s" could not be opened', $this->lockFileName), 1386520596);
        }

        $this->applyFlock($exclusiveLock);

        $fstat = fstat($this->filePointer);
        $stat = @stat($this->lockFileName);
        // Make sure that the file did not get unlinked between the fopen and the actual flock
        // This will always be true on windows, because 'ino' stat will always be 0, but unlink is not possible on opened files anyway
        if ($stat !== false && $stat['ino'] === $fstat['ino']) {
            return true;
        }

        flock($this->filePointer, LOCK_UN);
        fclose($this->filePointer);
        $this->filePointer = null;

        usleep(100 + rand(0, 100));
        return false;
    }
1176757
def lock(&block)
      lockfile = Lockfile.new File.join(GitModel.repo.path, 'refs/heads', branch + '.lock')
      begin
        lockfile.lock
        yield
      ensure
        lockfile.unlock
      end
    end
1259282
public function setFileLock($file_lock)
    {
        if (empty($file_lock) && $file_lock !== false) {
            throw new PageCacheException(__CLASS__ . ' file lock can not be empty. To disable set to boolean false.');
        }
        $this->file_lock = $file_lock;
    }
1067888
protected function openLockFile()
    {
        if (!is_dir(dirname($this->lockfilePath))) {
            // Suppress warning on mkdir - may be created by another process
            @mkdir(dirname($this->lockfilePath), 0744, true);
        }
        $this->lockfp = fopen($this->lockfilePath, 'w+');
    }