Example usage for org.eclipse.jgit.internal.storage.file LockFile write

List of usage examples for org.eclipse.jgit.internal.storage.file LockFile write

Introduction

In this page you can find the example usage for org.eclipse.jgit.internal.storage.file LockFile write.

Prototype

public void write(byte[] content) throws IOException 

Source Link

Document

Write arbitrary data to the temporary file.

Usage

From source file:com.collabnet.gerrit.SecureStoreJasypt.java

License:Apache License

private static void saveSecure(final FileBasedConfig sec) throws IOException {
    if (FileUtil.modified(sec)) {
        final byte[] out = Constants.encode(sec.toText());
        final File path = sec.getFile();
        final LockFile lf = new LockFile(path, FS.DETECTED);
        if (!lf.lock()) {
            throw new IOException("Cannot lock " + path);
        }//from w  ww .  j  a  va2s  .  c  o  m
        try {
            FileUtil.chmod(0600, new File(path.getParentFile(), path.getName() + ".lock"));
            lf.write(out);
            if (!lf.commit()) {
                throw new IOException("Cannot commit write to " + path);
            }
        } finally {
            lf.unlock();
        }
    }
}

From source file:com.google.gerrit.server.git.LocalDiskRepositoryManager.java

License:Apache License

@Override
public void setProjectDescription(final Project.NameKey name, final String description) {
    // Update git's description file, in case gitweb is being used
    ///*from ww  w  . ja va 2 s .c  o  m*/
    try (Repository e = openRepository(name)) {
        final String old = getProjectDescription(e);
        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();
        }
    } catch (IOException e) {
        log.error("Cannot update description for " + name, e);
    }
}

From source file:com.googlesource.gerrit.plugins.secureconfig.SecureConfigStore.java

License:Apache License

private void saveSecure(final FileBasedConfig sec) throws IOException {
    if (FileUtil.modified(sec)) {
        final byte[] out = Constants.encode(sec.toText());
        final File path = sec.getFile();
        final LockFile lf = new LockFile(path);
        if (!lf.lock()) {
            throw new IOException("Cannot lock " + path);
        }/*w  w w. j  a  v a 2  s  .c  om*/
        try {
            FileUtil.chmod(0600, new File(path.getParentFile(), path.getName() + ".lock"));
            lf.write(out);
            if (!lf.commit()) {
                throw new IOException("Cannot commit write to " + path);
            }
        } finally {
            lf.unlock();
        }
    }
}