Package org.eclipse.jgit.storage.file

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


    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


  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

  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

  public void syncCQs(File file, FS fs, URL base, String username,
      String password) throws IOException, ConfigInvalidException {
    if (!file.getParentFile().exists())
      file.getParentFile().mkdirs();

    LockFile lf = new LockFile(file, fs);
    if (!lf.lock())
      throw new IOException(MessageFormat.format(IpLogText.get().cannotLock, file));
    try {
      FileBasedConfig cfg = new FileBasedConfig(file, fs);
      cfg.load();
      loadFrom(cfg);

      IPZillaQuery ipzilla = new IPZillaQuery(base, username, password);
      Set<CQ> current = ipzilla.getCQs(projects);

      for (CQ cq : sort(current, CQ.COMPARATOR)) {
        String id = Long.toString(cq.getID());

        set(cfg, S_CQ, id, K_DESCRIPTION, cq.getDescription());
        set(cfg, S_CQ, id, K_LICENSE, cq.getLicense());
        set(cfg, S_CQ, id, K_USE, cq.getUse());
        set(cfg, S_CQ, id, K_STATE, cq.getState());
        set(cfg, S_CQ, id, K_COMMENTS, cq.getComments());
      }

      for (CQ cq : cqs) {
        if (!current.contains(cq))
          cfg.unsetSection(S_CQ, Long.toString(cq.getID()));
      }

      lf.write(Constants.encode(cfg.toText()));
      if (!lf.commit())
        throw new IOException(MessageFormat.format(IpLogText.get().cannotWrite, file));
    } finally {
      lf.unlock();
    }
  }
View Full Code Here

    log.scan(db, rw.parseCommit(start), version);

    if (output != null) {
      if (!output.getParentFile().exists())
        output.getParentFile().mkdirs();
      LockFile lf = new LockFile(output, db.getFS());
      if (!lf.lock())
        throw die(MessageFormat.format(CLIText.get().cannotLock, output));
      try {
        OutputStream os = lf.getOutputStream();
        try {
          log.writeTo(os);
        } finally {
          os.close();
        }
        if (!lf.commit())
          throw die(MessageFormat.format(CLIText.get().cannotWrite, output));
      } finally {
        lf.unlock();
      }
    } else {
      log.writeTo(System.out);
      System.out.flush();
    }
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

  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

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.