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
 
20
package org.apache.sshd.common.file.nativefs;
21
 
22
import java.io.File;
23
 
24
import org.apache.sshd.common.Session;
25
import org.apache.sshd.common.file.FileSystemFactory;
26
import org.apache.sshd.common.file.FileSystemView;
27
import org.slf4j.Logger;
28
import org.slf4j.LoggerFactory;
29
 
30
/**
31
 * Native file system factory. It uses the OS file system.
32
 *
33
 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
34
 */
35
public class NativeFileSystemFactory implements FileSystemFactory {
36
 
37
    private final Logger LOG = LoggerFactory.getLogger(NativeFileSystemFactory.class);
38
 
39
    private boolean createHome;
40
 
41
    private boolean caseInsensitive;
42
 
43
    /**
44
     * Should the home directories be created automatically
45
     * @return true if the file system will create the home directory if not available
46
     */
47
    public boolean isCreateHome() {
48
        return createHome;
49
    }
50
 
51
    /**
52
     * Set if the home directories be created automatically
53
     * @param createHome true if the file system will create the home directory if not available
54
     */
55
 
56
    public void setCreateHome(boolean createHome) {
57
        this.createHome = createHome;
58
    }
59
 
60
    /**
61
     * Is this file system case insensitive.
62
     * Enabling might cause problems when working against case-sensitive file systems, like on Linux
63
     * @return true if this file system is case insensitive
64
     */
65
    public boolean isCaseInsensitive() {
66
        return caseInsensitive;
67
    }
68
 
69
    /**
70
     * Should this file system be case insensitive.
71
     * Enabling might cause problems when working against case-sensitive file systems, like on Linux
72
     * @param caseInsensitive true if this file system should be case insensitive
73
     */
74
    public void setCaseInsensitive(boolean caseInsensitive) {
75
        this.caseInsensitive = caseInsensitive;
76
    }
77
 
78
    /**
79
     * Create the appropriate user file system view.
80
     */
81
    public FileSystemView createFileSystemView(Session session) {
82
        String userName = session.getUsername();
83
        // create home if does not exist
84
        if (createHome) {
85
            String homeDirStr = "/home/" + userName;
86
            File homeDir = new File(homeDirStr);
87
            if (homeDir.isFile()) {
88
                LOG.warn("Not a directory :: " + homeDirStr);
89
//                    throw new FtpException("Not a directory :: " + homeDirStr);
90
            }
91
            if ((!homeDir.exists()) && (!homeDir.mkdirs())) {
92
                LOG.warn("Cannot create user home :: " + homeDirStr);
93
//                    throw new FtpException("Cannot create user home :: "
94
//                            + homeDirStr);
95
            }
96
        }
97
 
98
        FileSystemView fsView = new NativeFileSystemView(userName, caseInsensitive);
99
        return fsView;
100
    }
101
}