1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.storage.file;
12
13 import java.io.File;
14 import java.io.IOException;
15
16 import org.eclipse.jgit.lib.Constants;
17 import org.eclipse.jgit.transport.PackLock;
18 import org.eclipse.jgit.util.FS;
19 import org.eclipse.jgit.util.FileUtils;
20
21
22
23
24
25 public class PackLockImpl implements PackLock {
26 private final File keepFile;
27
28
29
30
31
32
33
34
35
36 public PackLockImpl(File packFile, FS fs) {
37 final File p = packFile.getParentFile();
38 final String n = packFile.getName();
39 keepFile = new File(p, n.substring(0, n.length() - 5) + ".keep");
40 }
41
42
43
44
45
46
47
48
49
50
51 public boolean lock(String msg) throws IOException {
52 if (msg == null)
53 return false;
54 if (!msg.endsWith("\n"))
55 msg += "\n";
56 final LockFile lf = new LockFile(keepFile);
57 if (!lf.lock())
58 return false;
59 lf.write(Constants.encode(msg));
60 return lf.commit();
61 }
62
63 @Override
64 public void unlock() throws IOException {
65 FileUtils.delete(keepFile);
66 }
67 }