File indexing completed on 2024-12-22 04:41:40
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Erik Duisters <e.duisters1@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 package org.kde.kdeconnect.Plugins.SftpPlugin; 0008 0009 import org.apache.sshd.common.file.SshFile; 0010 0011 import java.io.InputStream; 0012 import java.io.OutputStream; 0013 import java.util.Calendar; 0014 import java.util.Collections; 0015 import java.util.EnumSet; 0016 import java.util.HashMap; 0017 import java.util.List; 0018 import java.util.Map; 0019 0020 //TODO: ls .. and ls / only show .. and / respectively I would expect a listing 0021 //TODO: cd .. to / does not work and prints "Can't change directory: Can't check target" 0022 class RootFile implements SshFile { 0023 private final boolean exists; 0024 private final String userName; 0025 private final List<SshFile> files; 0026 0027 RootFile(List<SshFile> files, String userName, boolean exits) { 0028 this.files = files; 0029 this.userName = userName; 0030 this.exists = exits; 0031 } 0032 0033 public String getAbsolutePath() { 0034 return "/"; 0035 } 0036 0037 public String getName() { 0038 return "/"; 0039 } 0040 0041 public Map<Attribute, Object> getAttributes(boolean followLinks) { 0042 Map<Attribute, Object> attrs = new HashMap<>(); 0043 0044 attrs.put(Attribute.Size, 0); 0045 attrs.put(Attribute.Owner, userName); 0046 attrs.put(Attribute.Group, userName); 0047 0048 EnumSet<Permission> p = EnumSet.noneOf(Permission.class); 0049 p.add(Permission.UserExecute); 0050 p.add(Permission.GroupExecute); 0051 p.add(Permission.OthersExecute); 0052 attrs.put(Attribute.Permissions, p); 0053 0054 long now = Calendar.getInstance().getTimeInMillis(); 0055 attrs.put(Attribute.LastAccessTime, now); 0056 attrs.put(Attribute.LastModifiedTime, now); 0057 0058 attrs.put(Attribute.IsSymbolicLink, false); 0059 attrs.put(Attribute.IsDirectory, true); 0060 attrs.put(Attribute.IsRegularFile, false); 0061 0062 return attrs; 0063 } 0064 0065 public void setAttributes(Map<Attribute, Object> attributes) { 0066 } 0067 0068 public Object getAttribute(Attribute attribute, boolean followLinks) { 0069 return null; 0070 } 0071 0072 public void setAttribute(Attribute attribute, Object value) { 0073 } 0074 0075 public String readSymbolicLink() { 0076 return ""; 0077 } 0078 0079 public void createSymbolicLink(SshFile destination) { 0080 } 0081 0082 public String getOwner() { 0083 return null; 0084 } 0085 0086 public boolean isDirectory() { 0087 return true; 0088 } 0089 0090 public boolean isFile() { 0091 return false; 0092 } 0093 0094 public boolean doesExist() { 0095 return exists; 0096 } 0097 0098 public boolean isReadable() { 0099 return true; 0100 } 0101 0102 public boolean isWritable() { 0103 return false; 0104 } 0105 0106 public boolean isExecutable() { 0107 return true; 0108 } 0109 0110 public boolean isRemovable() { 0111 return false; 0112 } 0113 0114 public SshFile getParentFile() { 0115 return this; 0116 } 0117 0118 public long getLastModified() { 0119 return 0; 0120 } 0121 0122 public boolean setLastModified(long time) { 0123 return false; 0124 } 0125 0126 public long getSize() { 0127 return 0; 0128 } 0129 0130 public boolean mkdir() { 0131 return false; 0132 } 0133 0134 public boolean delete() { 0135 return false; 0136 } 0137 0138 public boolean create() { 0139 return false; 0140 } 0141 0142 public void truncate() { 0143 } 0144 0145 public boolean move(SshFile destination) { 0146 return false; 0147 } 0148 0149 public List<SshFile> listSshFiles() { 0150 return Collections.unmodifiableList(files); 0151 } 0152 0153 public OutputStream createOutputStream(long offset) { 0154 return null; 0155 } 0156 0157 public InputStream createInputStream(long offset) { 0158 return null; 0159 } 0160 0161 public void handleClose() { 0162 } 0163 }