Package org.eclipse.jgit.internal.storage.file

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


  private void detachHead() throws IOException {
    final String head = db.getFullBranch();
    final ObjectId id = db.resolve(Constants.HEAD);
    if (!ObjectId.isId(head) && id != null) {
      final LockFile lf;
      lf = new LockFile(new File(db.getDirectory(), Constants.HEAD), db.getFS());
      if (!lf.lock())
        throw new IOException(MessageFormat.format(CLIText.get().cannotLock, Constants.HEAD));
      lf.write(id);
      if (!lf.commit())
        throw new IOException(CLIText.get().cannotDeatchHEAD);
    }
  }
View Full Code Here


    new RefWriter(refs.values()) {
      @Override
      protected void writeFile(final String name, final byte[] content)
          throws IOException {
        final File file = new File(db.getDirectory(), name);
        final LockFile lck = new LockFile(file, db.getFS());
        if (!lck.lock())
          throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file));
        try {
          lck.write(content);
        } catch (IOException ioe) {
          throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file));
        }
        if (!lck.commit())
          throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file));
      }
    }.writePackedRefs();
  }
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

  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"), //$NON-NLS-1$
        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

    return new File(packdir, "pack-" + name.name() + t);
  }

  private void writeFile(final File p, final byte[] bin) throws IOException,
      ObjectWritingException {
    final LockFile lck = new LockFile(p, db.getFS());
    if (!lck.lock())
      throw new ObjectWritingException("Can't write " + p);
    try {
      lck.write(bin);
    } catch (IOException ioe) {
      throw new ObjectWritingException("Can't write " + p);
    }
    if (!lck.commit())
      throw new ObjectWritingException("Can't write " + p);
  }
View Full Code Here

      out = bos.toByteArray();
    } else {
      out = Constants.encode(text);
    }

    final LockFile lf = new LockFile(getFile(), fs);
    if (!lf.lock())
      throw new LockFailedException(getFile());
    try {
      lf.setNeedSnapshot(true);
      lf.write(out);
      if (!lf.commit())
        throw new IOException(MessageFormat.format(JGitText.get().cannotCommitWriteTo, getFile()));
    } finally {
      lf.unlock();
    }
    snapshot = lf.getCommitSnapshot();
    hash = hash(out);
    // notify the listeners
    fireConfigChangedEvent();
  }
View Full Code Here

    assertNotNull(commit1);
    writeTrashFile("file.txt", "content2");
    git.add().addFilepattern("file.txt").call();
    assertNotNull(git.commit().setMessage("edit file").call());

    LockFile lf = new LockFile(db.getIndexFile(), db.getFS());
    assertTrue(lf.lock());
    try {
      git.checkout().setName(commit1.name()).call();
      fail("JGitInternalException not thrown");
    } catch (JGitInternalException e) {
      assertTrue(e.getCause() instanceof LockFailedException);
      lf.unlock();
      git.checkout().setName(commit1.name()).call();
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.internal.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.