Skip to content

Package: UNIXInbox

UNIXInbox

nameinstructionbranchcomplexitylinemethod
UNIXInbox(String, String)
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
closeLock()
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
equals(Object)
M: 22 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
hashCode()
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lock(String)
M: 27 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
openLock(String)
M: 71 C: 0
0%
M: 13 C: 0
0%
M: 8 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%
touchlock()
M: 5 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
unlock()
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.eclipse.angus.mail.mbox;
18:
19: import java.io.File;
20: import java.io.IOException;
21: import java.io.RandomAccessFile;
22:
23: public class UNIXInbox extends UNIXFolder implements InboxFile {
24: private final String user;
25:
26: private static final long serialVersionUID = 651261842162777620L;
27:
28: /*
29: * Superclass UNIXFile loads the library containing all the
30: * native code and sets the "loaded" flag if successful.
31: */
32:
33: public UNIXInbox(String user, String name) {
34: super(name);
35: this.user = user;
36:• if (user == null)
37: throw new NullPointerException("user name is null in UNIXInbox");
38: }
39:
40: public boolean lock(String mode) {
41:• if (lockType == NATIVE) {
42:• if (!loaded)
43: return false;
44:• if (!maillock(user, 5))
45: return false;
46: }
47:• if (!super.lock(mode)) {
48:• if (loaded)
49: mailunlock();
50: return false;
51: }
52: return true;
53: }
54:
55: public void unlock() {
56: super.unlock();
57:• if (loaded)
58: mailunlock();
59: }
60:
61: public void touchlock() {
62:• if (loaded)
63: touchlock0();
64: }
65:
66: private transient RandomAccessFile lockfile; // the user's ~/.Maillock file
67: private transient String lockfileName; // its name
68:
69: public boolean openLock(String mode) {
70:• if (mode.equals("r"))
71: return true;
72:• if (lockfileName == null) {
73: String home = System.getProperty("user.home");
74: lockfileName = home + File.separator + ".Maillock";
75: }
76: try {
77: lockfile = new RandomAccessFile(lockfileName, mode);
78: boolean ret;
79:• switch (lockType) {
80: case NONE:
81: ret = true;
82: break;
83: case NATIVE:
84: default:
85: ret = UNIXFile.lock(lockfile.getFD(), mode);
86: break;
87: case JAVA:
88: ret = lockfile.getChannel().
89:• tryLock(0L, Long.MAX_VALUE, !mode.equals("rw")) != null;
90: break;
91: }
92:• if (!ret)
93: closeLock();
94: return ret;
95: } catch (IOException ex) {
96: }
97: return false;
98: }
99:
100: public void closeLock() {
101:• if (lockfile == null)
102: return;
103: try {
104: lockfile.close();
105: } catch (IOException ex) {
106: } finally {
107: lockfile = null;
108: }
109: }
110:
111: public boolean equals(Object o) {
112:• if (!(o instanceof UNIXInbox))
113: return false;
114: UNIXInbox other = (UNIXInbox) o;
115:• return user.equals(other.user) && super.equals(other);
116: }
117:
118: public int hashCode() {
119: return super.hashCode() + user.hashCode();
120: }
121:
122: private native boolean maillock(String user, int retryCount);
123:
124: private native void mailunlock();
125:
126: private native void touchlock0();
127: }