public function release()

in src/shipit/ShipItScopedFlock.php [95:124]


  public function release(): void {
    invariant($this->released === false, "Tried to release lock twice");

    switch ($this->destructBehavior) {
      case ShipItScopedFlockOperation::MAKE_SHARED:
        $this->debugWrite('Downgrading to shared lock...', self::DEBUG_RELEASE);
        break;
      case ShipItScopedFlockOperation::RELEASE:
        $this->debugWrite('Releasing lock...', self::DEBUG_RELEASE);
        break;
      default:
        throw new \Exception('Invalid release operation');
    }

    $flock_result = PHP\flock($this->fp, $this->destructBehavior);
    if (!$flock_result) {
      throw new \Exception('Failed to weaken lock');
    }
    $this->released = true;
    if ($this->destructBehavior === ShipItScopedFlockOperation::RELEASE) {
      try {
        PHP\fclose($this->fp);
        /* HH_IGNORE_ERROR[2049] __PHPStdLib */
        /* HH_IGNORE_ERROR[4107] __PHPStdLib */
        \unlink($this->path);
      } catch (\Exception $_e) {
        // if these files already don't exist do nothing
      }
    }
  }