Package org.eclipse.jgit.storage.file

Examples of org.eclipse.jgit.storage.file.LockFile


  private void updateFETCH_HEAD(final FetchResult result) throws IOException {
    File meta = transport.local.getDirectory();
    if (meta == null)
      return;
    final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD"),
        transport.local.getFS());
    try {
      if (lock.lock()) {
        final Writer w = new OutputStreamWriter(lock.getOutputStream());
        try {
          for (final FetchHeadRecord h : fetchHeadUpdates) {
            h.write(w);
            result.add(h);
          }
        } finally {
          w.close();
        }
        lock.commit();
      }
    } finally {
      lock.unlock();
    }
  }
View Full Code Here


   *             hold the lock.
   */
  public boolean lock() throws IOException {
    if (liveFile == null)
      throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile);
    final LockFile tmp = new LockFile(liveFile, fs);
    if (tmp.lock()) {
      tmp.setNeedStatInformation(true);
      myLock = tmp;
      return true;
    }
    return false;
  }
View Full Code Here

   * @throws IOException
   *             the output file could not be created. The caller no longer
   *             holds the lock.
   */
  public void write() throws IOException {
    final LockFile tmp = myLock;
    requireLocked(tmp);
    try {
      writeTo(new SafeBufferedOutputStream(tmp.getOutputStream()));
    } catch (IOException err) {
      tmp.unlock();
      throw err;
    } catch (RuntimeException err) {
      tmp.unlock();
      throw err;
    } catch (Error err) {
      tmp.unlock();
      throw err;
    }
  }
View Full Code Here

   *         old data.
   * @throws IllegalStateException
   *             the lock is not held.
   */
  public boolean commit() {
    final LockFile tmp = myLock;
    requireLocked(tmp);
    myLock = null;
    if (!tmp.commit())
      return false;
    snapshot = tmp.getCommitSnapshot();
    if (indexChangedListener != null
        && !Arrays.equals(readIndexChecksum, writeIndexChecksum))
      indexChangedListener.onIndexChanged(new IndexChangedEvent());
    return true;
  }
View Full Code Here

   * Unlock this file and abort this change.
   * <p>
   * The temporary file (if created) is deleted before returning.
   */
  public void unlock() {
    final LockFile tmp = myLock;
    if (tmp != null) {
      myLock = null;
      tmp.unlock();
    }
  }
View Full Code Here

   *             hold the lock.
   */
  public boolean lock() throws IOException {
    if (liveFile == null)
      throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile);
    final LockFile tmp = new LockFile(liveFile, fs);
    if (tmp.lock()) {
      tmp.setNeedStatInformation(true);
      myLock = tmp;
      return true;
    }
    return false;
  }
View Full Code Here

   * @throws IOException
   *             the output file could not be created. The caller no longer
   *             holds the lock.
   */
  public void write() throws IOException {
    final LockFile tmp = myLock;
    requireLocked(tmp);
    try {
      writeTo(new BufferedOutputStream(tmp.getOutputStream()));
    } catch (IOException err) {
      tmp.unlock();
      throw err;
    } catch (RuntimeException err) {
      tmp.unlock();
      throw err;
    } catch (Error err) {
      tmp.unlock();
      throw err;
    }
  }
View Full Code Here

   *         old data.
   * @throws IllegalStateException
   *             the lock is not held.
   */
  public boolean commit() {
    final LockFile tmp = myLock;
    requireLocked(tmp);
    myLock = null;
    if (!tmp.commit())
      return false;
    snapshot = tmp.getCommitSnapshot();
    return true;
  }
View Full Code Here

   * Unlock this file and abort this change.
   * <p>
   * The temporary file (if created) is deleted before returning.
   */
  public void unlock() {
    final LockFile tmp = myLock;
    if (tmp != null) {
      myLock = null;
      tmp.unlock();
    }
  }
View Full Code Here

  private void updateFETCH_HEAD(final FetchResult result) throws IOException {
    File meta = transport.local.getDirectory();
    if (meta == null)
      return;
    final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD"),
        transport.local.getFS());
    try {
      if (lock.lock()) {
        final Writer w = new OutputStreamWriter(lock.getOutputStream());
        try {
          for (final FetchHeadRecord h : fetchHeadUpdates) {
            h.write(w);
            result.add(h);
          }
        } finally {
          w.close();
        }
        lock.commit();
      }
    } finally {
      lock.unlock();
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.storage.file.LockFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.