rename worky again

This commit is contained in:
RafayAhmad7548 2025-08-10 07:16:13 +05:00
parent a45378a094
commit 3f12b14e8a
2 changed files with 37 additions and 14 deletions

View file

@ -35,6 +35,13 @@ class Remove extends SftpCommand {
Remove(this.dirEntry, this.path); Remove(this.dirEntry, this.path);
} }
class Rename extends SftpCommand {
final String oldpath;
final String newpath;
Rename(this.oldpath, this.newpath);
}
class SftpWorker { class SftpWorker {
@ -163,7 +170,15 @@ class SftpWorker {
} }
sendPort.send((id, 0)); sendPort.send((id, 0));
} }
on SftpStatusError catch (e) { on SftpStatusError catch (e) {
sendPort.send((id, RemoteError(e.message, '')));
}
case Rename(:final oldpath, :final newpath):
try {
await sftpClient.rename(oldpath, newpath);
sendPort.send((id, 0));
}
on SftpStatusError catch (e) {
sendPort.send((id, RemoteError(e.message, ''))); sendPort.send((id, RemoteError(e.message, '')));
} }
} }
@ -232,4 +247,12 @@ class SftpWorker {
await completer.future; await completer.future;
} }
Future<void> rename(String oldpath, String newpath) async {
final completer = Completer.sync();
final id = _idCounter++;
_activeRequests[id] = completer;
_commands.send((id, Rename(oldpath, newpath)));
await completer.future;
}
} }

View file

@ -51,19 +51,19 @@ class OperationButtons extends StatelessWidget {
TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')), TextButton(onPressed: () => Navigator.pop(context), child: Text('Cancel')),
TextButton( TextButton(
onPressed: () async { onPressed: () async {
// try { try {
// await sftpWorker.rename('${path}${dirEntry.filename}', '${widget.path}${newNameController.text}'); await sftpWorker.rename('$path${dirEntry.filename}', '$path${newNameController.text}');
// _listDir(); listDir();
// } }
// on SftpStatusError catch (e) { on SftpStatusError catch (e) {
// if (context.mounted) { if (context.mounted) {
// ScaffoldMessenger.of(context).showSnackBar(_buildErrorSnackBar(context, e.message)); ScaffoldMessenger.of(context).showSnackBar(buildErrorSnackBar(context, e.message));
// } }
// } }
// if (context.mounted) { if (context.mounted) {
// Navigator.pop(context); Navigator.pop(context);
// } }
//
}, },
child: Text('Rename') child: Text('Rename')
), ),