import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
-import java.nio.channels.FileLock;
-import java.nio.channels.OverlappingFileLockException;
import java.text.MessageFormat;
import org.eclipse.jgit.JGitText;
private final File lck;
- private FileLock fLck;
-
private boolean haveLck;
private FileOutputStream os;
haveLck = true;
try {
os = new FileOutputStream(lck);
- try {
- fLck = os.getChannel().tryLock();
- if (fLck == null)
- throw new OverlappingFileLockException();
- } catch (OverlappingFileLockException ofle) {
- // We cannot use unlock() here as this file is not
- // held by us, but we thought we created it. We must
- // not delete it, as it belongs to some other process.
- //
- haveLck = false;
- try {
- os.close();
- } catch (IOException ioe) {
- // Fail by returning haveLck = false.
- }
- os = null;
- }
} catch (IOException ioe) {
unlock();
throw ioe;
} else {
os.write(content);
}
- fLck.release();
os.close();
os = null;
} catch (IOException ioe) {
out.flush();
if (fsync)
os.getChannel().force(true);
- fLck.release();
out.close();
os = null;
} catch (IOException ioe) {
*/
public void unlock() {
if (os != null) {
- if (fLck != null) {
- try {
- fLck.release();
- } catch (IOException ioe) {
- // Huh?
- }
- fLck = null;
- }
try {
os.close();
} catch (IOException ioe) {