0
|
1
|
|
2 package com.trilead.ssh2;
|
|
3
|
|
4 /**
|
|
5 * A <code>SFTPv3FileAttributes</code> object represents detail information
|
|
6 * about a file on the server. Not all fields may/must be present.
|
|
7 *
|
|
8 * @author Christian Plattner, plattner@trilead.com
|
|
9 * @version $Id: SFTPv3FileAttributes.java,v 1.2 2008/04/01 12:38:09 cplattne Exp $
|
|
10 */
|
|
11
|
|
12 public class SFTPv3FileAttributes {
|
|
13 /**
|
|
14 * The SIZE attribute. <code>NULL</code> if not present.
|
|
15 */
|
|
16 public Long size = null;
|
|
17
|
|
18 /**
|
|
19 * The UID attribute. <code>NULL</code> if not present.
|
|
20 */
|
|
21 public Integer uid = null;
|
|
22
|
|
23 /**
|
|
24 * The GID attribute. <code>NULL</code> if not present.
|
|
25 */
|
|
26 public Integer gid = null;
|
|
27
|
|
28 /**
|
|
29 * The POSIX permissions. <code>NULL</code> if not present.
|
|
30 * <p>
|
|
31 * Here is a list:
|
|
32 * <p>
|
|
33 * <pre>Note: these numbers are all OCTAL.
|
|
34 *
|
|
35 * S_IFMT 0170000 bitmask for the file type bitfields
|
|
36 * S_IFSOCK 0140000 socket
|
|
37 * S_IFLNK 0120000 symbolic link
|
|
38 * S_IFREG 0100000 regular file
|
|
39 * S_IFBLK 0060000 block device
|
|
40 * S_IFDIR 0040000 directory
|
|
41 * S_IFCHR 0020000 character device
|
|
42 * S_IFIFO 0010000 fifo
|
|
43 * S_ISUID 0004000 set UID bit
|
|
44 * S_ISGID 0002000 set GID bit
|
|
45 * S_ISVTX 0001000 sticky bit
|
|
46 *
|
|
47 * S_IRWXU 00700 mask for file owner permissions
|
|
48 * S_IRUSR 00400 owner has read permission
|
|
49 * S_IWUSR 00200 owner has write permission
|
|
50 * S_IXUSR 00100 owner has execute permission
|
|
51 * S_IRWXG 00070 mask for group permissions
|
|
52 * S_IRGRP 00040 group has read permission
|
|
53 * S_IWGRP 00020 group has write permission
|
|
54 * S_IXGRP 00010 group has execute permission
|
|
55 * S_IRWXO 00007 mask for permissions for others (not in group)
|
|
56 * S_IROTH 00004 others have read permission
|
|
57 * S_IWOTH 00002 others have write permisson
|
|
58 * S_IXOTH 00001 others have execute permission
|
|
59 * </pre>
|
|
60 */
|
|
61 public Integer permissions = null;
|
|
62
|
|
63 /**
|
|
64 * The ATIME attribute. Represented as seconds from Jan 1, 1970 in UTC.
|
|
65 * <code>NULL</code> if not present.
|
|
66 */
|
|
67 public Long atime = null;
|
|
68
|
|
69 /**
|
|
70 * The MTIME attribute. Represented as seconds from Jan 1, 1970 in UTC.
|
|
71 * <code>NULL</code> if not present.
|
|
72 */
|
|
73 public Long mtime = null;
|
|
74
|
|
75 /**
|
|
76 * Checks if this entry is a directory.
|
|
77 *
|
|
78 * @return Returns true if permissions are available and they indicate
|
|
79 * that this entry represents a directory.
|
|
80 */
|
|
81 public boolean isDirectory() {
|
|
82 if (permissions == null)
|
|
83 return false;
|
|
84
|
|
85 return ((permissions.intValue() & 0040000) != 0);
|
|
86 }
|
|
87
|
|
88 /**
|
|
89 * Checks if this entry is a regular file.
|
|
90 *
|
|
91 * @return Returns true if permissions are available and they indicate
|
|
92 * that this entry represents a regular file.
|
|
93 */
|
|
94 public boolean isRegularFile() {
|
|
95 if (permissions == null)
|
|
96 return false;
|
|
97
|
|
98 return ((permissions.intValue() & 0100000) != 0);
|
|
99 }
|
|
100
|
|
101 /**
|
|
102 * Checks if this entry is a a symlink.
|
|
103 *
|
|
104 * @return Returns true if permissions are available and they indicate
|
|
105 * that this entry represents a symlink.
|
|
106 */
|
|
107 public boolean isSymlink() {
|
|
108 if (permissions == null)
|
|
109 return false;
|
|
110
|
|
111 return ((permissions.intValue() & 0120000) != 0);
|
|
112 }
|
|
113
|
|
114 /**
|
|
115 * Turn the POSIX permissions into a 7 digit octal representation.
|
|
116 * Note: the returned value is first masked with <code>0177777</code>.
|
|
117 *
|
|
118 * @return <code>NULL</code> if permissions are not available.
|
|
119 */
|
|
120 public String getOctalPermissions() {
|
|
121 if (permissions == null)
|
|
122 return null;
|
|
123
|
|
124 String res = Integer.toString(permissions.intValue() & 0177777, 8);
|
|
125 StringBuffer sb = new StringBuffer();
|
|
126 int leadingZeros = 7 - res.length();
|
|
127
|
|
128 while (leadingZeros > 0) {
|
|
129 sb.append('0');
|
|
130 leadingZeros--;
|
|
131 }
|
|
132
|
|
133 sb.append(res);
|
|
134 return sb.toString();
|
|
135 }
|
|
136 }
|