fix: rename file

This commit is contained in:
lollipopkit🏳️‍⚧️
2024-09-22 16:06:09 +08:00
parent eab06abcaf
commit 47aedb2f2e
11 changed files with 164 additions and 142 deletions

View File

@@ -1,35 +0,0 @@
import 'package:fl_lib/fl_lib.dart';
class AbsolutePath {
String _path;
final _prePath = <String>[];
AbsolutePath(this._path);
String get path => _path;
/// Update path, not set path
set path(String newPath) {
_prePath.add(_path);
if (newPath == '..') {
_path = _path.substring(0, _path.lastIndexOf('/'));
if (_path == '') {
_path = '/';
}
return;
}
if (newPath.startsWith('/')) {
_path = newPath;
return;
}
_path = _path.joinPath(newPath, seperator: '/');
}
bool undo() {
if (_prePath.isEmpty) {
return false;
}
_path = _prePath.removeLast();
return true;
}
}

View File

@@ -1,12 +1,49 @@
import 'package:dartssh2/dartssh2.dart';
import 'package:server_box/data/model/sftp/absolute_path.dart';
import 'package:fl_lib/fl_lib.dart';
/// Remote server only can be linux-like system, so use '/' as seperator
const _sep = '/';
class SftpBrowserStatus {
final List<SftpName> files = [];
final AbsolutePath path = AbsolutePath('/');
final path = _AbsolutePath(_sep);
SftpClient? client;
SftpBrowserStatus(SSHClient client) {
client.sftp().then((value) => this.client = value);
}
}
class _AbsolutePath {
String _path;
final _prePath = <String>[];
_AbsolutePath(this._path);
String get path => _path;
/// Update path, not set path
set path(String newPath) {
_prePath.add(_path);
if (newPath == '..') {
_path = _path.substring(0, _path.lastIndexOf(_sep));
if (_path == '') {
_path = _sep;
}
return;
}
if (newPath.startsWith(_sep)) {
_path = newPath;
return;
}
_path = _path.joinPath(newPath, seperator: _sep);
}
bool undo() {
if (_prePath.isEmpty) {
return false;
}
_path = _prePath.removeLast();
return true;
}
}