flyshell 1.4.10__tar.gz → 1.4.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flyshell-1.4.10/src/flyshell.egg-info → flyshell-1.4.11}/PKG-INFO +1 -1
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/diskops.c +16 -1
- flyshell-1.4.11/c_src/diskops/posix/mv.c +52 -0
- flyshell-1.4.11/c_src/diskops/win32/mv.c +74 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/setup.py +2 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/constants.py +2 -3
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/core/directory.py +1 -2
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/native/diskops_handler.py +65 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/native/legacy/diskops.py +25 -0
- {flyshell-1.4.10 → flyshell-1.4.11/src/flyshell.egg-info}/PKG-INFO +1 -1
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell.egg-info/SOURCES.txt +2 -2
- {flyshell-1.4.10 → flyshell-1.4.11}/tests/test_diskops_ext.py +39 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/tests/test_diskops_lgc.py +13 -0
- flyshell-1.4.10/src/flyshell/builtin/diskops.py +0 -350
- flyshell-1.4.10/tests/test_diskops_old.py +0 -41
- {flyshell-1.4.10 → flyshell-1.4.11}/LICENSE +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/MANIFEST.in +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/README.md +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/posix/cat.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/posix/cp.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/posix/dir.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/posix/mkdir.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/posix/rename.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/posix/rm.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/posix/rmdir.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/posix/touch.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/shared/dir_types.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/shared/dir_types.h +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/shared/native_errors.h +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/shared/win32_utf.h +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/win32/cat.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/win32/cp.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/win32/dir.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/win32/mkdir.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/win32/rename.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/win32/rm.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/win32/rmdir.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/c_src/diskops/win32/touch.c +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/pyproject.toml +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/setup.cfg +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/__init__.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/abstract/__init__.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/abstract/base_cmd.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/abstract/base_plugin.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/abstract/parent_cmd.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/accounts/__init__.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/accounts/auth.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/bin/__init__.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/builtin/__init__.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/builtin/fs.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/builtin/pkg.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/builtin/system.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/builtin/utils.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/core/__init__.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/core/console.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/core/data.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/main.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/native/__init__.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/native/diskops_bridge.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/native/legacy/__init__.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/startup/__init__.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/startup/deps.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/startup/env.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell/startup/loader.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell.egg-info/dependency_links.txt +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell.egg-info/entry_points.txt +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell.egg-info/requires.txt +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/src/flyshell.egg-info/top_level.txt +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/tests/test_auth.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/tests/test_data.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/tests/test_deps.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/tests/test_directory.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/tests/test_env.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/tests/test_fs.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/tests/test_loader.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/tests/test_pkg.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/tests/test_security.py +0 -0
- {flyshell-1.4.10 → flyshell-1.4.11}/tests/test_utils.py +0 -0
|
@@ -21,6 +21,8 @@ Result remove_item(const char *path, bool recursive);
|
|
|
21
21
|
|
|
22
22
|
Result copy_item(const char *src, const char *dst, bool force);
|
|
23
23
|
|
|
24
|
+
Result move_item(const char *src, const char *dst, bool force);
|
|
25
|
+
|
|
24
26
|
static PyObject *method_ping(PyObject *self, PyObject *args) {
|
|
25
27
|
return PyLong_FromLong(42);
|
|
26
28
|
}
|
|
@@ -152,6 +154,18 @@ static PyObject *method_cp(PyObject *self, PyObject *args) {
|
|
|
152
154
|
return Py_BuildValue("(is)", (int)res, "");
|
|
153
155
|
}
|
|
154
156
|
|
|
157
|
+
static PyObject *method_mv(PyObject *self, PyObject *args) {
|
|
158
|
+
const char *src;
|
|
159
|
+
const char *dst;
|
|
160
|
+
int force = 0;
|
|
161
|
+
if (!PyArg_ParseTuple(args, "ss|p", &src, &dst, &force)) {
|
|
162
|
+
return NULL;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
Result res = move_item(src, dst, force != 0);
|
|
166
|
+
return Py_BuildValue("(is)", (int)res, "");
|
|
167
|
+
}
|
|
168
|
+
|
|
155
169
|
static PyMethodDef DiskopsMethods[] = {
|
|
156
170
|
{"ping", method_ping, METH_NOARGS, "Health check ping."},
|
|
157
171
|
{"cat", method_cat, METH_VARARGS, "Read file content natively."},
|
|
@@ -161,7 +175,8 @@ static PyMethodDef DiskopsMethods[] = {
|
|
|
161
175
|
{"rename", method_rename, METH_VARARGS, "Rename file or directory natively."},
|
|
162
176
|
{"rmdir", method_rmdir, METH_VARARGS, "Remove directory natively."},
|
|
163
177
|
{"rm", method_rm, METH_VARARGS, "Remove file or directory natively."},
|
|
164
|
-
{"cp", method_cp, METH_VARARGS, "Copy
|
|
178
|
+
{"cp", method_cp, METH_VARARGS, "Copy file or directory natively."},
|
|
179
|
+
{"mv", method_mv, METH_VARARGS, "Move file or directory natively."},
|
|
165
180
|
{NULL, NULL, 0, NULL},
|
|
166
181
|
};
|
|
167
182
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// c_src/diskops/posix/mv.c
|
|
2
|
+
|
|
3
|
+
#include "../shared/native_errors.h"
|
|
4
|
+
#include <errno.h>
|
|
5
|
+
#include <stdbool.h>
|
|
6
|
+
#include <stdio.h>
|
|
7
|
+
#include <sys/stat.h>
|
|
8
|
+
|
|
9
|
+
Result copy_item(const char *src, const char *dst, bool force);
|
|
10
|
+
Result remove_item(const char *path, bool recursive);
|
|
11
|
+
|
|
12
|
+
Result move_item(const char *src, const char *dst, bool force) {
|
|
13
|
+
if (!src || src[0] == '\0' || !dst || dst[0] == '\0') {
|
|
14
|
+
return ERR_INVALID_PATH;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
struct stat src_st;
|
|
18
|
+
if (lstat(src, &src_st) != 0) {
|
|
19
|
+
return map_posix_errno(errno);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
struct stat dst_st;
|
|
23
|
+
if (lstat(dst, &dst_st) == 0) {
|
|
24
|
+
if (src_st.st_dev == dst_st.st_dev && src_st.st_ino == dst_st.st_ino) {
|
|
25
|
+
return ERR_SAME_FILE;
|
|
26
|
+
}
|
|
27
|
+
if (!force) {
|
|
28
|
+
return ERR_EXISTS;
|
|
29
|
+
}
|
|
30
|
+
if (S_ISDIR(dst_st.st_mode)) {
|
|
31
|
+
Result rm_res = remove_item(dst, true);
|
|
32
|
+
if (rm_res != SUCCESS) {
|
|
33
|
+
return rm_res;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (rename(src, dst) == 0) {
|
|
39
|
+
return SUCCESS;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (errno != EXDEV) {
|
|
43
|
+
return map_posix_errno(errno);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
Result cp_res = copy_item(src, dst, true);
|
|
47
|
+
if (cp_res != SUCCESS) {
|
|
48
|
+
return cp_res;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return remove_item(src, true);
|
|
52
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// c_src/diskops/win32/mv.c
|
|
2
|
+
|
|
3
|
+
#include "../shared/native_errors.h"
|
|
4
|
+
#include "../shared/win32_utf.h"
|
|
5
|
+
#include <stdbool.h>
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
#include <windows.h>
|
|
8
|
+
|
|
9
|
+
Result copy_item(const char *src, const char *dst, bool force);
|
|
10
|
+
Result remove_item(const char *path, bool recursive);
|
|
11
|
+
|
|
12
|
+
Result move_item(const char *src, const char *dst, bool force) {
|
|
13
|
+
if (!src || src[0] == '\0' || !dst || dst[0] == '\0') {
|
|
14
|
+
return ERR_INVALID_PATH;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
wchar_t *wsrc = utf8_to_wide(src);
|
|
18
|
+
if (!wsrc) {
|
|
19
|
+
return ERR_INVALID_PATH;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
wchar_t *wdst = utf8_to_wide(dst);
|
|
23
|
+
if (!wdst) {
|
|
24
|
+
free(wsrc);
|
|
25
|
+
return ERR_INVALID_PATH;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
DWORD src_attrs = GetFileAttributesW(wsrc);
|
|
29
|
+
if (src_attrs == INVALID_FILE_ATTRIBUTES) {
|
|
30
|
+
DWORD err = GetLastError();
|
|
31
|
+
free(wsrc);
|
|
32
|
+
free(wdst);
|
|
33
|
+
return map_win32_error(err);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
DWORD dst_attrs = GetFileAttributesW(wdst);
|
|
37
|
+
if (dst_attrs != INVALID_FILE_ATTRIBUTES) {
|
|
38
|
+
if (!force) {
|
|
39
|
+
free(wsrc);
|
|
40
|
+
free(wdst);
|
|
41
|
+
return ERR_EXISTS;
|
|
42
|
+
}
|
|
43
|
+
if ((dst_attrs & FILE_ATTRIBUTE_DIRECTORY) != 0) {
|
|
44
|
+
Result rm_res = remove_item(dst, true);
|
|
45
|
+
if (rm_res != SUCCESS) {
|
|
46
|
+
free(wsrc);
|
|
47
|
+
free(wdst);
|
|
48
|
+
return rm_res;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
DWORD flags = force ? MOVEFILE_REPLACE_EXISTING : 0;
|
|
54
|
+
if (MoveFileExW(wsrc, wdst, flags) != 0) {
|
|
55
|
+
free(wsrc);
|
|
56
|
+
free(wdst);
|
|
57
|
+
return SUCCESS;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
DWORD err = GetLastError();
|
|
61
|
+
free(wsrc);
|
|
62
|
+
free(wdst);
|
|
63
|
+
|
|
64
|
+
if (err != ERROR_NOT_SAME_DEVICE) {
|
|
65
|
+
return map_win32_error(err);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Result cp_res = copy_item(src, dst, true);
|
|
69
|
+
if (cp_res != SUCCESS) {
|
|
70
|
+
return cp_res;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return remove_item(src, true);
|
|
74
|
+
}
|
|
@@ -16,6 +16,7 @@ if sys.platform == "win32":
|
|
|
16
16
|
"c_src/diskops/win32/cp.c",
|
|
17
17
|
"c_src/diskops/win32/dir.c",
|
|
18
18
|
"c_src/diskops/win32/mkdir.c",
|
|
19
|
+
"c_src/diskops/win32/mv.c",
|
|
19
20
|
"c_src/diskops/win32/rename.c",
|
|
20
21
|
"c_src/diskops/win32/rm.c",
|
|
21
22
|
"c_src/diskops/win32/rmdir.c",
|
|
@@ -29,6 +30,7 @@ else:
|
|
|
29
30
|
"c_src/diskops/posix/cp.c",
|
|
30
31
|
"c_src/diskops/posix/dir.c",
|
|
31
32
|
"c_src/diskops/posix/mkdir.c",
|
|
33
|
+
"c_src/diskops/posix/mv.c",
|
|
32
34
|
"c_src/diskops/posix/rename.c",
|
|
33
35
|
"c_src/diskops/posix/rm.c",
|
|
34
36
|
"c_src/diskops/posix/rmdir.c",
|
|
@@ -5,8 +5,8 @@ import os
|
|
|
5
5
|
import platform
|
|
6
6
|
import time
|
|
7
7
|
|
|
8
|
-
BUILD =
|
|
9
|
-
VERSION = "1.4.
|
|
8
|
+
BUILD = 165
|
|
9
|
+
VERSION = "1.4.11"
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def _resolve_app_dir() -> Path:
|
|
@@ -58,7 +58,6 @@ REQUIRED_COMPONENTS = [
|
|
|
58
58
|
"bin/__init__.py",
|
|
59
59
|
"builtin",
|
|
60
60
|
"builtin/__init__.py",
|
|
61
|
-
"builtin/diskops.py",
|
|
62
61
|
"builtin/fs.py",
|
|
63
62
|
"builtin/pkg.py",
|
|
64
63
|
"builtin/system.py",
|
|
@@ -4,7 +4,6 @@ from flyshell import constants as c
|
|
|
4
4
|
from flyshell.abstract.base_cmd import BaseCmd
|
|
5
5
|
from flyshell.abstract.parent_cmd import ParentCmd
|
|
6
6
|
from flyshell.accounts import auth
|
|
7
|
-
from flyshell.builtin import diskops as diskops_legacy
|
|
8
7
|
from flyshell.builtin import fs, pkg, system, utils
|
|
9
8
|
from flyshell.core import data
|
|
10
9
|
from flyshell.native import diskops_handler as diskops
|
|
@@ -66,7 +65,7 @@ INSTALLED_COMMANDS: list[BaseCmd] = [
|
|
|
66
65
|
utils.Kill(),
|
|
67
66
|
auth.Lock(),
|
|
68
67
|
diskops.MkDir(),
|
|
69
|
-
|
|
68
|
+
diskops.Move(),
|
|
70
69
|
system.OpenFile(),
|
|
71
70
|
pkg.Pkg(),
|
|
72
71
|
utils.Reboot(),
|
|
@@ -204,6 +204,71 @@ class Dir(BaseCmd):
|
|
|
204
204
|
return (0, "\n".join(lines))
|
|
205
205
|
|
|
206
206
|
|
|
207
|
+
class Move(BaseCmd):
|
|
208
|
+
name = "mv"
|
|
209
|
+
description = "Move or relocate files and directories"
|
|
210
|
+
min_args = 2
|
|
211
|
+
options = "Source, then destination"
|
|
212
|
+
aliases = ["move"]
|
|
213
|
+
|
|
214
|
+
def execute(self, args):
|
|
215
|
+
force = ("-f" in args) or ("--force" in args)
|
|
216
|
+
flags = {"-f", "--force"}
|
|
217
|
+
path_tokens = [arg for arg in args if arg not in flags]
|
|
218
|
+
if len(path_tokens) < 2:
|
|
219
|
+
return (
|
|
220
|
+
1,
|
|
221
|
+
"\nCommand Error: 'mv' requires both a source and a destination path.\n",
|
|
222
|
+
)
|
|
223
|
+
raw_src = path_tokens[0].strip("\"'")
|
|
224
|
+
raw_dst = path_tokens[1].strip("\"'")
|
|
225
|
+
src_path = Path(raw_src).expanduser().resolve()
|
|
226
|
+
dst_path = Path(raw_dst).expanduser().resolve()
|
|
227
|
+
if not src_path.exists():
|
|
228
|
+
return (1, f"\nSystem Error: Source '{raw_src}' not found.\n")
|
|
229
|
+
if src_path == src_path.parent or str(src_path) == src_path.anchor:
|
|
230
|
+
return (
|
|
231
|
+
1,
|
|
232
|
+
"\nSecurity Error: Flyshell has blocked moving the root filesystem.\n",
|
|
233
|
+
)
|
|
234
|
+
flyshell_dirs = [
|
|
235
|
+
c.APP_DIR.resolve(),
|
|
236
|
+
c.PACKAGE_ROOT.resolve(),
|
|
237
|
+
c.PROJECT_ROOT.resolve(),
|
|
238
|
+
]
|
|
239
|
+
for protected in flyshell_dirs:
|
|
240
|
+
if src_path == protected or src_path.is_relative_to(protected):
|
|
241
|
+
return (
|
|
242
|
+
1,
|
|
243
|
+
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
244
|
+
f"Source '{raw_src}' contains or belongs to Flyshell system files.\n",
|
|
245
|
+
)
|
|
246
|
+
if dst_path.exists() and dst_path.is_dir():
|
|
247
|
+
final_dst = dst_path / src_path.name
|
|
248
|
+
else:
|
|
249
|
+
final_dst = dst_path
|
|
250
|
+
if final_dst.exists() and not force:
|
|
251
|
+
try:
|
|
252
|
+
confirm = (
|
|
253
|
+
input(
|
|
254
|
+
f"\nDestination '{final_dst.name}' already exists. Overwrite? [y/n]: "
|
|
255
|
+
)
|
|
256
|
+
.strip()
|
|
257
|
+
.lower()
|
|
258
|
+
)
|
|
259
|
+
except (KeyboardInterrupt, EOFError):
|
|
260
|
+
return (1, "\nMove cancelled by user.\n")
|
|
261
|
+
if confirm != "y":
|
|
262
|
+
return (0, "\nOperation cancelled. No files were moved.\n")
|
|
263
|
+
if bridge.has_native_support() and hasattr(bridge._native, "mv"):
|
|
264
|
+
code, _ = bridge._native.mv(str(src_path), str(final_dst), force)
|
|
265
|
+
else:
|
|
266
|
+
code, _ = legacy.lgc_mv(src_path, final_dst, force)
|
|
267
|
+
if code != 0:
|
|
268
|
+
return bridge.translate_error(code, raw_src)
|
|
269
|
+
return (0, f"\nSUCCESS! Moved '{src_path.name}' -> '{final_dst}'\n")
|
|
270
|
+
|
|
271
|
+
|
|
207
272
|
class MkDir(BaseCmd):
|
|
208
273
|
name = "mkdir"
|
|
209
274
|
description = "Create a new directory from the current working directory"
|
|
@@ -99,6 +99,31 @@ def lgc_mkdir(target_path: Path, parents: bool = False) -> tuple[int, str]:
|
|
|
99
99
|
return (-99, "") # ERR_UNKNOWN
|
|
100
100
|
|
|
101
101
|
|
|
102
|
+
def lgc_mv(src_path: Path, dst_path: Path, force: bool = False) -> tuple[int, str]:
|
|
103
|
+
if not src_path.exists():
|
|
104
|
+
return (-1, "") # ERR_NOT_FOUND
|
|
105
|
+
if src_path == dst_path:
|
|
106
|
+
return (-7, "") # ERR_SAME_FILE
|
|
107
|
+
if dst_path.exists() and not force:
|
|
108
|
+
return (-5, "") # ERR_EXISTS
|
|
109
|
+
try:
|
|
110
|
+
if dst_path.exists() and force:
|
|
111
|
+
if dst_path.is_dir():
|
|
112
|
+
shutil.rmtree(dst_path)
|
|
113
|
+
else:
|
|
114
|
+
os.remove(dst_path)
|
|
115
|
+
shutil.move(str(src_path), str(dst_path))
|
|
116
|
+
return (0, "") # SUCCESS
|
|
117
|
+
except shutil.SameFileError:
|
|
118
|
+
return (-7, "") # ERR_SAME_FILE
|
|
119
|
+
except PermissionError:
|
|
120
|
+
return (-2, "") # ERR_PERMISSION
|
|
121
|
+
except OSError:
|
|
122
|
+
return (-13, "") # ERR_IO
|
|
123
|
+
except Exception:
|
|
124
|
+
return (-99, "") # ERR_UNKNOWN
|
|
125
|
+
|
|
126
|
+
|
|
102
127
|
def lgc_rename(src_path: Path, dst_path: Path) -> tuple[int, str]:
|
|
103
128
|
if not src_path.exists():
|
|
104
129
|
return (-1, "") # ERR_NOT_FOUND
|
|
@@ -8,6 +8,7 @@ c_src/diskops/posix/cat.c
|
|
|
8
8
|
c_src/diskops/posix/cp.c
|
|
9
9
|
c_src/diskops/posix/dir.c
|
|
10
10
|
c_src/diskops/posix/mkdir.c
|
|
11
|
+
c_src/diskops/posix/mv.c
|
|
11
12
|
c_src/diskops/posix/rename.c
|
|
12
13
|
c_src/diskops/posix/rm.c
|
|
13
14
|
c_src/diskops/posix/rmdir.c
|
|
@@ -20,6 +21,7 @@ c_src/diskops/win32/cat.c
|
|
|
20
21
|
c_src/diskops/win32/cp.c
|
|
21
22
|
c_src/diskops/win32/dir.c
|
|
22
23
|
c_src/diskops/win32/mkdir.c
|
|
24
|
+
c_src/diskops/win32/mv.c
|
|
23
25
|
c_src/diskops/win32/rename.c
|
|
24
26
|
c_src/diskops/win32/rm.c
|
|
25
27
|
c_src/diskops/win32/rmdir.c
|
|
@@ -41,7 +43,6 @@ src/flyshell/accounts/__init__.py
|
|
|
41
43
|
src/flyshell/accounts/auth.py
|
|
42
44
|
src/flyshell/bin/__init__.py
|
|
43
45
|
src/flyshell/builtin/__init__.py
|
|
44
|
-
src/flyshell/builtin/diskops.py
|
|
45
46
|
src/flyshell/builtin/fs.py
|
|
46
47
|
src/flyshell/builtin/pkg.py
|
|
47
48
|
src/flyshell/builtin/system.py
|
|
@@ -65,7 +66,6 @@ tests/test_deps.py
|
|
|
65
66
|
tests/test_directory.py
|
|
66
67
|
tests/test_diskops_ext.py
|
|
67
68
|
tests/test_diskops_lgc.py
|
|
68
|
-
tests/test_diskops_old.py
|
|
69
69
|
tests/test_env.py
|
|
70
70
|
tests/test_fs.py
|
|
71
71
|
tests/test_loader.py
|
|
@@ -11,6 +11,45 @@ def test_native_extension_loaded():
|
|
|
11
11
|
assert bridge._native.ping() == 42
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
def test_native_mv_file_and_directory(tmp_path):
|
|
15
|
+
cmd = handler.Move()
|
|
16
|
+
src_file = tmp_path / "move_src.txt"
|
|
17
|
+
src_file.write_text("relocate me", encoding="utf-8")
|
|
18
|
+
dst_file = tmp_path / "move_dst.txt"
|
|
19
|
+
exit_code, msg = cmd.execute([str(src_file), str(dst_file)])
|
|
20
|
+
assert exit_code == 0
|
|
21
|
+
assert "Moved" in msg
|
|
22
|
+
assert not src_file.exists()
|
|
23
|
+
assert dst_file.read_text(encoding="utf-8") == "relocate me"
|
|
24
|
+
replacement = tmp_path / "new_src.txt"
|
|
25
|
+
replacement.write_text("overwritten", encoding="utf-8")
|
|
26
|
+
exit_code, msg = cmd.execute(["-f", str(replacement), str(dst_file)])
|
|
27
|
+
assert exit_code == 0
|
|
28
|
+
assert not replacement.exists()
|
|
29
|
+
assert dst_file.read_text(encoding="utf-8") == "overwritten"
|
|
30
|
+
src_dir = tmp_path / "dir_to_move"
|
|
31
|
+
src_dir.mkdir()
|
|
32
|
+
(src_dir / "item.txt").write_text("inside", encoding="utf-8")
|
|
33
|
+
target_parent = tmp_path / "dest_holder"
|
|
34
|
+
target_parent.mkdir()
|
|
35
|
+
exit_code, msg = cmd.execute([str(src_dir), str(target_parent)])
|
|
36
|
+
assert exit_code == 0
|
|
37
|
+
assert not src_dir.exists()
|
|
38
|
+
assert (target_parent / "dir_to_move" / "item.txt").read_text(encoding="utf-8") == "inside"
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_native_mv_errors(tmp_path):
|
|
42
|
+
cmd = handler.Move()
|
|
43
|
+
exit_code, msg = cmd.execute([str(tmp_path / "missing.txt"), str(tmp_path / "out.txt")])
|
|
44
|
+
assert exit_code == 1
|
|
45
|
+
assert "not found" in msg
|
|
46
|
+
a = tmp_path / "a.txt"
|
|
47
|
+
b = tmp_path / "b.txt"
|
|
48
|
+
a.write_text("1", encoding="utf-8")
|
|
49
|
+
b.write_text("2", encoding="utf-8")
|
|
50
|
+
code, _ = bridge._native.mv(str(a), str(b), False)
|
|
51
|
+
assert code == -5 # ERR_EXISTS
|
|
52
|
+
|
|
14
53
|
def test_native_cp_file_and_directory(tmp_path):
|
|
15
54
|
cmd = handler.Copy()
|
|
16
55
|
src_file = tmp_path / "src.txt"
|
|
@@ -12,6 +12,19 @@ def force_legacy_backend(monkeypatch):
|
|
|
12
12
|
monkeypatch.setattr(bridge, "has_native_support", lambda: False)
|
|
13
13
|
|
|
14
14
|
|
|
15
|
+
def test_legacy_mv_file_and_errors(tmp_path):
|
|
16
|
+
cmd = handler.Move()
|
|
17
|
+
src_file = tmp_path / "lgc_move_src.txt"
|
|
18
|
+
src_file.write_text("data", encoding="utf-8")
|
|
19
|
+
dst_file = tmp_path / "lgc_move_dst.txt"
|
|
20
|
+
exit_code, msg = cmd.execute([str(src_file), str(dst_file)])
|
|
21
|
+
assert exit_code == 0
|
|
22
|
+
assert not src_file.exists()
|
|
23
|
+
assert dst_file.read_text(encoding="utf-8") == "data"
|
|
24
|
+
code, _ = legacy.lgc_mv(tmp_path / "ghost.txt", tmp_path / "out.txt", force=False)
|
|
25
|
+
assert code == -1 # ERR_NOT_FOUND
|
|
26
|
+
|
|
27
|
+
|
|
15
28
|
def test_legacy_cp_file_and_directory(tmp_path):
|
|
16
29
|
cmd = handler.Copy()
|
|
17
30
|
src_file = tmp_path / "lgc_src.txt"
|
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
# src/flyshell/builtin/diskops.py
|
|
2
|
-
|
|
3
|
-
from flyshell import constants as c
|
|
4
|
-
from flyshell.abstract.base_cmd import BaseCmd
|
|
5
|
-
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
import os
|
|
8
|
-
import shutil
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class Copy(BaseCmd):
|
|
12
|
-
name = "cp"
|
|
13
|
-
description = "Copy files or directories to a new destination"
|
|
14
|
-
min_args = 2
|
|
15
|
-
options = "Source, then destination"
|
|
16
|
-
aliases = ["copy"]
|
|
17
|
-
|
|
18
|
-
def execute(self, args):
|
|
19
|
-
force = ("-f" in args) or ("--force" in args)
|
|
20
|
-
flags = {"-f", "--force"}
|
|
21
|
-
path_tokens = [arg for arg in args if arg not in flags]
|
|
22
|
-
if len(path_tokens) < 2:
|
|
23
|
-
return (
|
|
24
|
-
1,
|
|
25
|
-
"\nCommand Error: 'cp' requires both a source and destination path.\n",
|
|
26
|
-
)
|
|
27
|
-
raw_src = path_tokens[0].strip("\"'")
|
|
28
|
-
raw_dst = path_tokens[1].strip("\"'")
|
|
29
|
-
src_path = Path(raw_src).expanduser().resolve()
|
|
30
|
-
dst_path = Path(raw_dst).expanduser().resolve()
|
|
31
|
-
if not src_path.exists():
|
|
32
|
-
return (1, f"\nSystem Error: Source '{raw_src}' not found.\n")
|
|
33
|
-
if dst_path.exists() and dst_path.is_dir():
|
|
34
|
-
final_dst = dst_path / src_path.name
|
|
35
|
-
else:
|
|
36
|
-
final_dst = dst_path
|
|
37
|
-
if final_dst.exists() and not force:
|
|
38
|
-
try:
|
|
39
|
-
confirm = (
|
|
40
|
-
input(
|
|
41
|
-
f"\nDestination '{final_dst.name}' already exists. Overwrite? [y/n]: "
|
|
42
|
-
)
|
|
43
|
-
.strip()
|
|
44
|
-
.lower()
|
|
45
|
-
)
|
|
46
|
-
except (KeyboardInterrupt, EOFError):
|
|
47
|
-
return (1, "\nCopy cancelled by user.\n")
|
|
48
|
-
if confirm != "y":
|
|
49
|
-
return (0, "\nOperation cancelled. No files were copied.\n")
|
|
50
|
-
try:
|
|
51
|
-
if src_path.is_dir():
|
|
52
|
-
shutil.copytree(src_path, final_dst, dirs_exist_ok=force)
|
|
53
|
-
return (
|
|
54
|
-
0,
|
|
55
|
-
f"\nSUCCESS! Copied directory '{src_path.name}' -> '{final_dst}'\n",
|
|
56
|
-
)
|
|
57
|
-
else:
|
|
58
|
-
shutil.copy2(src_path, final_dst)
|
|
59
|
-
return (
|
|
60
|
-
0,
|
|
61
|
-
f"\nSUCCESS! Copied file '{src_path.name}' -> '{final_dst}'\n",
|
|
62
|
-
)
|
|
63
|
-
except PermissionError:
|
|
64
|
-
return (
|
|
65
|
-
1,
|
|
66
|
-
f"\nSystem Error: Permission denied. Cannot copy to '{final_dst}'\n",
|
|
67
|
-
)
|
|
68
|
-
except shutil.SameFileError:
|
|
69
|
-
return (1, "\nSystem Error: Source and destination are the same.\n")
|
|
70
|
-
except Exception as e:
|
|
71
|
-
return (1, f"\nSystem Error: Failed to copy '{raw_src}' ({e})\n")
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
class Move(BaseCmd):
|
|
75
|
-
name = "mv"
|
|
76
|
-
description = "Move or relocate files and directories"
|
|
77
|
-
min_args = 2
|
|
78
|
-
options = "Source, then destination"
|
|
79
|
-
aliases = ["move"]
|
|
80
|
-
|
|
81
|
-
def execute(self, args):
|
|
82
|
-
force = ("-f" in args) or ("--force" in args)
|
|
83
|
-
flags = {"-f", "--force"}
|
|
84
|
-
path_tokens = [arg for arg in args if arg not in flags]
|
|
85
|
-
if len(path_tokens) < 2:
|
|
86
|
-
return (
|
|
87
|
-
1,
|
|
88
|
-
"\nCommand Error: 'mv' requires both a source and a destination path.\n",
|
|
89
|
-
)
|
|
90
|
-
raw_src = path_tokens[0].strip("\"'")
|
|
91
|
-
raw_dst = path_tokens[1].strip("\"'")
|
|
92
|
-
src_path = Path(raw_src).expanduser().resolve()
|
|
93
|
-
dst_path = Path(raw_dst).expanduser().resolve()
|
|
94
|
-
if not src_path.exists():
|
|
95
|
-
return (1, f"\nSystem Error: Source '{raw_src}' not found.\n")
|
|
96
|
-
if src_path == src_path.parent or str(src_path) == src_path.anchor:
|
|
97
|
-
return (
|
|
98
|
-
1,
|
|
99
|
-
"\nSecurity Error: Flyshell has blocked moving the root filesystem.\n",
|
|
100
|
-
)
|
|
101
|
-
flyshell_dirs = [
|
|
102
|
-
c.APP_DIR.resolve(),
|
|
103
|
-
c.PACKAGE_ROOT.resolve(),
|
|
104
|
-
c.PROJECT_ROOT.resolve(),
|
|
105
|
-
]
|
|
106
|
-
for protected in flyshell_dirs:
|
|
107
|
-
if src_path == protected or src_path.is_relative_to(protected):
|
|
108
|
-
return (
|
|
109
|
-
1,
|
|
110
|
-
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
111
|
-
f"Source '{raw_src}' contains or belongs to Flyshell system files.\n",
|
|
112
|
-
)
|
|
113
|
-
if dst_path.exists() and dst_path.is_dir():
|
|
114
|
-
final_dst = dst_path / src_path.name
|
|
115
|
-
else:
|
|
116
|
-
final_dst = dst_path
|
|
117
|
-
if final_dst.exists() and not force:
|
|
118
|
-
try:
|
|
119
|
-
confirm = (
|
|
120
|
-
input(
|
|
121
|
-
f"\nDestination '{final_dst.name}' already exists. Overwrite? [y/n]: "
|
|
122
|
-
)
|
|
123
|
-
.strip()
|
|
124
|
-
.lower()
|
|
125
|
-
)
|
|
126
|
-
except (KeyboardInterrupt, EOFError):
|
|
127
|
-
return (1, "\nMove cancelled by user.\n")
|
|
128
|
-
if confirm != "y":
|
|
129
|
-
return (0, "\nOperation cancelled. No files were moved.\n")
|
|
130
|
-
try:
|
|
131
|
-
shutil.move(str(src_path), str(final_dst))
|
|
132
|
-
return (0, f"\nSUCCESS! Moved '{src_path.name}' -> '{final_dst}'\n")
|
|
133
|
-
except PermissionError:
|
|
134
|
-
return (
|
|
135
|
-
1,
|
|
136
|
-
f"\nSystem Error: Permission denied. Cannot move to '{final_dst}'\n",
|
|
137
|
-
)
|
|
138
|
-
except shutil.SameFileError:
|
|
139
|
-
return (1, "\nSystem Error: Source and destination are the same.\n")
|
|
140
|
-
except Exception as e:
|
|
141
|
-
return (1, f"\nSystem Error: Failed to move '{raw_src}' ({e})\n")
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
class Rm(BaseCmd):
|
|
145
|
-
name = "rm"
|
|
146
|
-
description = "Remove files from the filesystem"
|
|
147
|
-
min_args = 1
|
|
148
|
-
options = "Target file"
|
|
149
|
-
aliases = ["del"]
|
|
150
|
-
|
|
151
|
-
def execute(self, args):
|
|
152
|
-
force = ("-f" in args) or ("--force" in args)
|
|
153
|
-
recursive = ("-r" in args) or ("--recursive" in args)
|
|
154
|
-
flags = {"-f", "--force", "-r", "--recursive"}
|
|
155
|
-
path_tokens = [arg for arg in args if arg not in flags]
|
|
156
|
-
if not path_tokens:
|
|
157
|
-
return (1, "\nCommand Error: No target file or directory specified.\n")
|
|
158
|
-
raw_target = " ".join(path_tokens).strip("\"'")
|
|
159
|
-
target_path = Path(raw_target).expanduser().resolve()
|
|
160
|
-
if not target_path.exists():
|
|
161
|
-
return (1, f"\nSystem Error: Target '{raw_target}' not found.\n")
|
|
162
|
-
if target_path == target_path.parent or str(target_path) == target_path.anchor:
|
|
163
|
-
return (
|
|
164
|
-
1,
|
|
165
|
-
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
166
|
-
"You cannot delete the root filesystem directory.\n",
|
|
167
|
-
)
|
|
168
|
-
critical_system_dirs = [
|
|
169
|
-
Path.home().parent.resolve(),
|
|
170
|
-
Path.home().resolve(),
|
|
171
|
-
]
|
|
172
|
-
if c.HOST_OS == "Windows":
|
|
173
|
-
system_drive = os.environ.get("SystemDrive", "C:")
|
|
174
|
-
critical_system_dirs.extend(
|
|
175
|
-
[
|
|
176
|
-
Path(f"{system_drive}\\Windows").resolve(),
|
|
177
|
-
Path(f"{system_drive}\\Program Files").resolve(),
|
|
178
|
-
Path(f"{system_drive}\\Program Files (x86)").resolve(),
|
|
179
|
-
]
|
|
180
|
-
)
|
|
181
|
-
else:
|
|
182
|
-
critical_system_dirs.extend(
|
|
183
|
-
[
|
|
184
|
-
Path("/bin").resolve(),
|
|
185
|
-
Path("/etc").resolve(),
|
|
186
|
-
Path("/usr").resolve(),
|
|
187
|
-
Path("/var").resolve(),
|
|
188
|
-
]
|
|
189
|
-
)
|
|
190
|
-
if target_path in critical_system_dirs:
|
|
191
|
-
return (
|
|
192
|
-
1,
|
|
193
|
-
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
194
|
-
f"Target '{raw_target}' is a protected operating system directory.\n",
|
|
195
|
-
)
|
|
196
|
-
if target_path == Path(os.getcwd()).resolve():
|
|
197
|
-
return (
|
|
198
|
-
1,
|
|
199
|
-
"\nSystem Error: Cannot remove current working directory.\n"
|
|
200
|
-
"Switch to a different directory using 'cd' first.\n",
|
|
201
|
-
)
|
|
202
|
-
flyshell_dirs = [
|
|
203
|
-
c.APP_DIR.resolve(),
|
|
204
|
-
c.PACKAGE_ROOT.resolve(),
|
|
205
|
-
c.PROJECT_ROOT.resolve(),
|
|
206
|
-
]
|
|
207
|
-
for protected in flyshell_dirs:
|
|
208
|
-
if target_path == protected or target_path.is_relative_to(protected):
|
|
209
|
-
return (
|
|
210
|
-
1,
|
|
211
|
-
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
212
|
-
f"Target '{raw_target}' contains or belongs to Flyshell system files.\n"
|
|
213
|
-
"If you wish to delete Flyshell, use the host.\n",
|
|
214
|
-
)
|
|
215
|
-
is_directory = target_path.is_dir()
|
|
216
|
-
if is_directory and not recursive:
|
|
217
|
-
return (
|
|
218
|
-
1,
|
|
219
|
-
f"\nCommand Error: '{raw_target}' is a directory.\n"
|
|
220
|
-
"Use '-r' or '--recursive' to remove directories.\n",
|
|
221
|
-
)
|
|
222
|
-
if not force:
|
|
223
|
-
target_type = "directory and all its contents" if is_directory else "file"
|
|
224
|
-
prompt_msg = f"\nAre you sure you want to permanently delete {target_type} '{raw_target}'? [y/n]: "
|
|
225
|
-
try:
|
|
226
|
-
confirm = input(prompt_msg).strip().lower()
|
|
227
|
-
except (KeyboardInterrupt, EOFError):
|
|
228
|
-
return (1, "\nDeletion cancelled by user.\n")
|
|
229
|
-
if confirm != "y":
|
|
230
|
-
return (0, "\nOperation cancelled. No files were deleted.\n")
|
|
231
|
-
try:
|
|
232
|
-
if is_directory:
|
|
233
|
-
shutil.rmtree(target_path)
|
|
234
|
-
return (
|
|
235
|
-
0,
|
|
236
|
-
f"\nSUCCESS! Deleted directory '{raw_target}' and all its contents.\n",
|
|
237
|
-
)
|
|
238
|
-
else:
|
|
239
|
-
os.remove(target_path)
|
|
240
|
-
return (0, f"\nSUCCESS! Deleted file '{raw_target}'\n")
|
|
241
|
-
except PermissionError:
|
|
242
|
-
return (
|
|
243
|
-
1,
|
|
244
|
-
f"\nSystem Error: Permission denied. Cannot remove '{raw_target}'\n",
|
|
245
|
-
)
|
|
246
|
-
except OSError as e:
|
|
247
|
-
return (
|
|
248
|
-
1,
|
|
249
|
-
f"\nSystem Error: Unable to remove '{raw_target}' ({e.strerror})\n",
|
|
250
|
-
)
|
|
251
|
-
except Exception as e:
|
|
252
|
-
return (
|
|
253
|
-
1,
|
|
254
|
-
f"\nSystem Error: Unexpected error removing '{raw_target}' ({e})\n",
|
|
255
|
-
)
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
class RmDir(BaseCmd):
|
|
259
|
-
name = "rmdir"
|
|
260
|
-
description = "Remove the specified directory"
|
|
261
|
-
min_args = 1
|
|
262
|
-
options = "Target directory"
|
|
263
|
-
aliases = []
|
|
264
|
-
|
|
265
|
-
def execute(self, args):
|
|
266
|
-
force = ("-f" in args) or ("--force" in args)
|
|
267
|
-
path_tokens = [arg for arg in args if arg not in ("-f", "--force")]
|
|
268
|
-
raw_target = " ".join(path_tokens).strip("\"'")
|
|
269
|
-
target_path = Path(raw_target).expanduser().resolve()
|
|
270
|
-
if target_path == target_path.parent or str(target_path) == target_path.anchor:
|
|
271
|
-
return (
|
|
272
|
-
1,
|
|
273
|
-
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
274
|
-
"You cannot delete the root filesystem directory.\n",
|
|
275
|
-
)
|
|
276
|
-
critical_system_dirs = [
|
|
277
|
-
Path.home().parent.resolve(),
|
|
278
|
-
Path.home().resolve(),
|
|
279
|
-
]
|
|
280
|
-
if c.HOST_OS == "Windows":
|
|
281
|
-
system_drive = os.environ.get("SystemDrive", "C:")
|
|
282
|
-
critical_system_dirs.extend(
|
|
283
|
-
[
|
|
284
|
-
Path(f"{system_drive}\\Windows").resolve(),
|
|
285
|
-
Path(f"{system_drive}\\Program Files").resolve(),
|
|
286
|
-
Path(f"{system_drive}\\Program Files (x86)").resolve(),
|
|
287
|
-
]
|
|
288
|
-
)
|
|
289
|
-
else:
|
|
290
|
-
critical_system_dirs.extend(
|
|
291
|
-
[
|
|
292
|
-
Path("/bin").resolve(),
|
|
293
|
-
Path("/etc").resolve(),
|
|
294
|
-
Path("/usr").resolve(),
|
|
295
|
-
Path("/var").resolve(),
|
|
296
|
-
]
|
|
297
|
-
)
|
|
298
|
-
if target_path in critical_system_dirs:
|
|
299
|
-
return (
|
|
300
|
-
1,
|
|
301
|
-
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
302
|
-
f"Target '{raw_target}' is a protected operating system directory.\n",
|
|
303
|
-
)
|
|
304
|
-
if target_path == Path(os.getcwd()).resolve():
|
|
305
|
-
return (
|
|
306
|
-
1,
|
|
307
|
-
"\nSystem Error: Cannot remove current working directory.\n"
|
|
308
|
-
"Switch to a different directory using 'cd' first.\n",
|
|
309
|
-
)
|
|
310
|
-
flyshell_dirs = [
|
|
311
|
-
c.APP_DIR.resolve(),
|
|
312
|
-
c.PACKAGE_ROOT.resolve(),
|
|
313
|
-
c.PROJECT_ROOT.resolve(),
|
|
314
|
-
]
|
|
315
|
-
for protected in flyshell_dirs:
|
|
316
|
-
if target_path == protected or target_path.is_relative_to(protected):
|
|
317
|
-
return (
|
|
318
|
-
1,
|
|
319
|
-
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
320
|
-
f"Target '{raw_target}' contains or belongs to Flyshell system files.\n"
|
|
321
|
-
"If you wish to delete Flyshell, use the host.\n",
|
|
322
|
-
)
|
|
323
|
-
try:
|
|
324
|
-
has_contents = any(target_path.iterdir())
|
|
325
|
-
if has_contents and not force:
|
|
326
|
-
return (
|
|
327
|
-
1,
|
|
328
|
-
f"\nDirectory Error: Directory '{raw_target}' is not empty.\n"
|
|
329
|
-
"Use '-f' or '--force' to remove a non-empty directory and its contents.\n",
|
|
330
|
-
)
|
|
331
|
-
if has_contents and force:
|
|
332
|
-
shutil.rmtree(target_path)
|
|
333
|
-
else:
|
|
334
|
-
os.rmdir(target_path)
|
|
335
|
-
return (0, f"\nSUCCESS! Removed directory '{raw_target}'\n")
|
|
336
|
-
except PermissionError:
|
|
337
|
-
return (
|
|
338
|
-
1,
|
|
339
|
-
f"\nSystem Error: Permission denied. Cannot delete '{raw_target}'\n",
|
|
340
|
-
)
|
|
341
|
-
except OSError as e:
|
|
342
|
-
return (
|
|
343
|
-
1,
|
|
344
|
-
f"\nSystem Error: Unable to remove directory '{raw_target}' ({e.strerror})\n",
|
|
345
|
-
)
|
|
346
|
-
except Exception as e:
|
|
347
|
-
return (
|
|
348
|
-
1,
|
|
349
|
-
f"\nSystem Error: Unexpected error removing '{raw_target}' ({e})\n",
|
|
350
|
-
)
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# tests/test_diskops_old.py
|
|
2
|
-
|
|
3
|
-
from flyshell.builtin import diskops
|
|
4
|
-
|
|
5
|
-
import pytest
|
|
6
|
-
|
|
7
|
-
pytestmark = pytest.mark.skip(reason="Deprecated features soon to be removed.")
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def test_copy_file_and_directory(tmp_path):
|
|
11
|
-
src_file = tmp_path / "source.txt"
|
|
12
|
-
src_file.write_text("payload")
|
|
13
|
-
dst_file = tmp_path / "dest.txt"
|
|
14
|
-
cmd = diskops.Copy()
|
|
15
|
-
code, msg = cmd.execute([str(src_file), str(dst_file)])
|
|
16
|
-
assert code == 0
|
|
17
|
-
assert dst_file.read_text() == "payload"
|
|
18
|
-
src_dir = tmp_path / "src_dir"
|
|
19
|
-
src_dir.mkdir()
|
|
20
|
-
(src_dir / "item.txt").write_text("inner")
|
|
21
|
-
dst_dir = tmp_path / "dst_dir"
|
|
22
|
-
code, msg = cmd.execute([str(src_dir), str(dst_dir)])
|
|
23
|
-
assert code == 0
|
|
24
|
-
assert (dst_dir / "item.txt").exists()
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def test_rm_file_and_directory_recursive(tmp_path):
|
|
28
|
-
target_file = tmp_path / "del.txt"
|
|
29
|
-
target_file.write_text("bye")
|
|
30
|
-
cmd = diskops.Rm()
|
|
31
|
-
code, msg = cmd.execute(["-f", str(target_file)])
|
|
32
|
-
assert code == 0
|
|
33
|
-
assert not target_file.exists()
|
|
34
|
-
target_dir = tmp_path / "sub_dir"
|
|
35
|
-
target_dir.mkdir()
|
|
36
|
-
code, msg = cmd.execute(["-f", str(target_dir)])
|
|
37
|
-
assert code == 1
|
|
38
|
-
assert "is a directory" in msg
|
|
39
|
-
code, msg = cmd.execute(["-f", "-r", str(target_dir)])
|
|
40
|
-
assert code == 0
|
|
41
|
-
assert not target_dir.exists()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|