Package org.eclipse.jgit.storage.file

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


  @Option(name = "--output", aliases = {"-o"}, required = true, metaVar = "FILE", usage = "File to write .proto into")
  private File file;

  @Override
  public int run() throws Exception {
    LockFile lock = new LockFile(file.getAbsoluteFile(), FS.DETECTED);
    if (!lock.lock()) {
      throw die("Cannot lock " + file);
    }
    try {
      JavaSchemaModel jsm = new JavaSchemaModel(ReviewDb.class);
      PrintWriter out = new PrintWriter(new BufferedWriter(
          new OutputStreamWriter(lock.getOutputStream(), "UTF-8")));
      try {
        String header;
        InputStream in = getClass().getResourceAsStream("ProtoGenHeader.txt");
        try {
          ByteBuffer buf = IO.readWholeStream(in, 1024);
          int ptr = buf.arrayOffset() + buf.position();
          int len = buf.remaining();
          header = new String(buf.array(), ptr, len, "UTF-8");
        } finally {
          in.close();
        }

        String version = com.google.gerrit.common.Version.getVersion();
        out.write(header.replace("@@VERSION@@", version));
        jsm.generateProto(out);
        out.flush();
      } finally {
        out.close();
      }
      if (!lock.commit()) {
        throw die("Could not write to " + file);
      }
    } finally {
      lock.unlock();
    }
    System.out.println("Created " + file.getPath());
    return 0;
  }
View Full Code Here


        if ((old == null && description == null)
            || (old != null && old.equals(description))) {
          return;
        }

        final LockFile f = new LockFile(new File(e.getDirectory(), "description"), FS.DETECTED);
        if (f.lock()) {
          String d = description;
          if (d != null) {
            d = d.trim();
            if (d.length() > 0) {
              d += "\n";
            }
          } else {
            d = "";
          }
          f.write(Constants.encode(d));
          f.commit();
        }
      } finally {
        e.close();
      }
    } catch (RepositoryNotFoundException e) {
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;
    lastModified = tmp.getCommitLastModified();
    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

   *             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();
    if (indexChangedListener != null
        && !Arrays.equals(readIndexChecksum, writeIndexChecksum))
      indexChangedListener.onIndexChanged(new IndexChangedEvent());
    return true;
  }
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.