Subversion Repositories Programming Utils

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
86 rm5248 1
/*
2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the
7
* "License"); you may not use this file except in compliance
8
* with the License. You may obtain a copy of the License at
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
12
* Unless required by applicable law or agreed to in writing,
13
* software distributed under the License is distributed on an
14
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
* KIND, either express or implied. See the License for the
16
* specific language governing permissions and limitations
17
* under the License.
18
*/
19
package org.apache.sshd.sftp.reply;
20
 
21
import org.apache.sshd.common.file.SshFile;
22
 
23
import static org.apache.sshd.sftp.subsystem.SftpConstants.*;
24
 
25
/**
26
 * Data container for file attributes in relies.
27
 * TODO: implement
28
 *
29
 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
30
 */
31
public class FileAttributes {
32
 
33
    int flags = 0;
34
    byte type;
35
    long size;
36
    long allocationSize;
37
    String owner;
38
    String group;
39
    int permissions;
40
    long accessTime;
41
    int accessTimeNanos;
42
    long modifyTime;
43
    int modifyTimeNanos;
44
    long createTime;
45
    int createTimeNanos;
46
    String acl;
47
    int attribBits;
48
    int attribBitsValid;
49
    byte textHint;
50
    String mimeType;
51
    int linkCount;
52
    String untranslatedName;
53
    int extended;
54
 
55
    public FileAttributes() {
56
    }
57
 
58
    public FileAttributes(SshFile file, int flags) {
59
        // Type
60
        if (file.isFile()) {
61
            setType((byte) SSH_FILEXFER_TYPE_REGULAR);
62
        } else if (file.isDirectory()) {
63
            setType((byte) SSH_FILEXFER_TYPE_DIRECTORY);
64
        } else {
65
            setType((byte) SSH_FILEXFER_TYPE_UNKNOWN);
66
        }
67
        // Size
68
        if ((flags & SSH_FILEXFER_ATTR_SIZE) != 0) {
69
            setSize(file.getSize());
70
        }
71
        // Permissions
72
        if ((flags & SSH_FILEXFER_ATTR_PERMISSIONS) != 0) {
73
            setPermissions((file.isReadable() ? S_IRUSR : 0) | (file.isWritable() ? S_IWUSR : 0) | (file.isExecutable() ? S_IXUSR : 0));
74
        }
75
        // Times
76
        if ((flags & SSH_FILEXFER_ATTR_ACCESSTIME) != 0) {
77
            setAccessTime(file.getLastModified() / 1000);
78
        }
79
        if ((flags & SSH_FILEXFER_ATTR_CREATETIME) != 0) {
80
            setCreateTime(file.getLastModified() / 1000);
81
        }
82
        if ((flags & SSH_FILEXFER_ATTR_MODIFYTIME) != 0) {
83
            setModifyTime(file.getLastModified() / 1000);
84
        }
85
    }
86
 
87
    public int getFlags() {
88
        return flags;
89
    }
90
 
91
    public byte getType() {
92
        return type;
93
    }
94
 
95
    public void setType(byte type) {
96
        this.type = type;
97
    }
98
 
99
    public long getSize() {
100
        return size;
101
    }
102
 
103
    public void setSize(long size) {
104
        this.flags |= SSH_FILEXFER_ATTR_SIZE;
105
        this.size = size;
106
    }
107
 
108
    public long getAllocationSize() {
109
        return allocationSize;
110
    }
111
 
112
    public void setAllocationSize(long allocationSize) {
113
        this.flags |= SSH_FILEXFER_ATTR_ALLOCATION_SIZE;
114
        this.allocationSize = allocationSize;
115
    }
116
 
117
    public String getOwner() {
118
        return owner;
119
    }
120
 
121
    public String getGroup() {
122
        return group;
123
    }
124
 
125
    public void setOwnerGroup(String owner, String group) {
126
        this.flags |= SSH_FILEXFER_ATTR_OWNERGROUP;
127
        this.owner = owner;
128
        this.group = group;
129
    }
130
 
131
    public int getPermissions() {
132
        return permissions;
133
    }
134
 
135
    public void setPermissions(int permissions) {
136
        this.flags |= SSH_FILEXFER_ATTR_PERMISSIONS;
137
        this.permissions = permissions;
138
    }
139
 
140
    public long getAccessTime() {
141
        return accessTime;
142
    }
143
 
144
    public void setAccessTime(long accessTime) {
145
        this.flags |= SSH_FILEXFER_ATTR_ACCESSTIME;
146
        this.accessTime = accessTime;
147
    }
148
 
149
    public long getModifyTime() {
150
        return modifyTime;
151
    }
152
 
153
    public void setModifyTime(long modifyTime) {
154
        this.flags |= SSH_FILEXFER_ATTR_MODIFYTIME;
155
        this.modifyTime = modifyTime;
156
    }
157
 
158
    public long getCreateTime() {
159
        return createTime;
160
    }
161
 
162
    public void setCreateTime(long createTime) {
163
        this.flags |= SSH_FILEXFER_ATTR_CREATETIME;
164
        this.createTime = createTime;
165
    }
166
}