Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/SftpPlugin/RootFile.java
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Erik Duisters <e.duisters1@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | package org.kde.kdeconnect.Plugins.SftpPlugin; | ||||
22 | | ||||
23 | import org.apache.sshd.common.file.SshFile; | ||||
24 | | ||||
25 | import java.io.IOException; | ||||
26 | import java.io.InputStream; | ||||
27 | import java.io.OutputStream; | ||||
28 | import java.util.Calendar; | ||||
29 | import java.util.Collections; | ||||
30 | import java.util.EnumSet; | ||||
31 | import java.util.HashMap; | ||||
32 | import java.util.List; | ||||
33 | import java.util.Map; | ||||
34 | | ||||
35 | //TODO: ls .. and ls / only show .. and / respectively I would expect a listing | ||||
36 | //TODO: cd .. to / does not work and prints "Can't change directory: Can't check target" | ||||
37 | class RootFile implements SshFile { | ||||
38 | private final boolean exists; | ||||
39 | private final String userName; | ||||
40 | private final List<SshFile> files; | ||||
41 | | ||||
42 | RootFile(List<SshFile> files, String userName, boolean exits) { | ||||
43 | this.files = files; | ||||
44 | this.userName = userName; | ||||
45 | this.exists = exits; | ||||
46 | } | ||||
47 | | ||||
48 | public String getAbsolutePath() { | ||||
49 | return "/"; | ||||
50 | } | ||||
51 | | ||||
52 | public String getName() { | ||||
53 | return "/"; | ||||
54 | } | ||||
55 | | ||||
56 | public Map<Attribute, Object> getAttributes(boolean followLinks) throws IOException { | ||||
57 | Map<Attribute, Object> attrs = new HashMap<>(); | ||||
58 | | ||||
59 | attrs.put(Attribute.Size, 0); | ||||
60 | attrs.put(Attribute.Owner, userName); | ||||
61 | attrs.put(Attribute.Group, userName); | ||||
62 | | ||||
63 | EnumSet<Permission> p = EnumSet.noneOf(Permission.class); | ||||
64 | p.add(Permission.UserExecute); | ||||
65 | p.add(Permission.GroupExecute); | ||||
66 | p.add(Permission.OthersExecute); | ||||
67 | attrs.put(Attribute.Permissions, p); | ||||
68 | | ||||
69 | long now = Calendar.getInstance().getTimeInMillis(); | ||||
70 | attrs.put(Attribute.LastAccessTime, now); | ||||
71 | attrs.put(Attribute.LastModifiedTime, now); | ||||
72 | | ||||
73 | attrs.put(Attribute.IsSymbolicLink, false); | ||||
74 | attrs.put(Attribute.IsDirectory, true); | ||||
75 | attrs.put(Attribute.IsRegularFile, false); | ||||
76 | | ||||
77 | return attrs; | ||||
78 | } | ||||
79 | | ||||
80 | public void setAttributes(Map<Attribute, Object> attributes) { | ||||
81 | } | ||||
82 | | ||||
83 | public Object getAttribute(Attribute attribute, boolean followLinks) { | ||||
84 | return null; | ||||
85 | } | ||||
86 | | ||||
87 | public void setAttribute(Attribute attribute, Object value) { | ||||
88 | } | ||||
89 | | ||||
90 | public String readSymbolicLink() { | ||||
91 | return null; | ||||
92 | } | ||||
93 | | ||||
94 | public void createSymbolicLink(SshFile destination) { | ||||
95 | } | ||||
96 | | ||||
97 | public String getOwner() { | ||||
98 | return null; | ||||
99 | } | ||||
100 | | ||||
101 | public boolean isDirectory() { | ||||
102 | return true; | ||||
103 | } | ||||
104 | | ||||
105 | public boolean isFile() { | ||||
106 | return false; | ||||
107 | } | ||||
108 | | ||||
109 | public boolean doesExist() { | ||||
110 | return exists; | ||||
111 | } | ||||
112 | | ||||
113 | public boolean isReadable() { | ||||
114 | return true; | ||||
115 | } | ||||
116 | | ||||
117 | public boolean isWritable() { | ||||
118 | return false; | ||||
119 | } | ||||
120 | | ||||
121 | public boolean isExecutable() { | ||||
122 | return true; | ||||
123 | } | ||||
124 | | ||||
125 | public boolean isRemovable() { | ||||
126 | return false; | ||||
127 | } | ||||
128 | | ||||
129 | public SshFile getParentFile() { | ||||
130 | return this; | ||||
131 | } | ||||
132 | | ||||
133 | public long getLastModified() { | ||||
134 | return 0; | ||||
135 | } | ||||
136 | | ||||
137 | public boolean setLastModified(long time) { | ||||
138 | return false; | ||||
139 | } | ||||
140 | | ||||
141 | public long getSize() { | ||||
142 | return 0; | ||||
143 | } | ||||
144 | | ||||
145 | public boolean mkdir() { | ||||
146 | return false; | ||||
147 | } | ||||
148 | | ||||
149 | public boolean delete() { | ||||
150 | return false; | ||||
151 | } | ||||
152 | | ||||
153 | public boolean create() { | ||||
154 | return false; | ||||
155 | } | ||||
156 | | ||||
157 | public void truncate() { | ||||
158 | } | ||||
159 | | ||||
160 | public boolean move(SshFile destination) { | ||||
161 | return false; | ||||
162 | } | ||||
163 | | ||||
164 | public List<SshFile> listSshFiles() { | ||||
165 | return Collections.unmodifiableList(files); | ||||
166 | } | ||||
167 | | ||||
168 | public OutputStream createOutputStream(long offset) { | ||||
169 | return null; | ||||
170 | } | ||||
171 | | ||||
172 | public InputStream createInputStream(long offset) { | ||||
173 | return null; | ||||
174 | } | ||||
175 | | ||||
176 | public void handleClose() { | ||||
177 | } | ||||
178 | } |