flyshell 1.4.6__tar.gz → 1.4.8__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.6/src/flyshell.egg-info → flyshell-1.4.8}/PKG-INFO +1 -1
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/diskops.c +28 -0
- flyshell-1.4.8/c_src/diskops/posix/rename.c +31 -0
- flyshell-1.4.8/c_src/diskops/posix/rmdir.c +98 -0
- flyshell-1.4.8/c_src/diskops/win32/rename.c +47 -0
- flyshell-1.4.8/c_src/diskops/win32/rmdir.c +131 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/setup.py +4 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/builtin/diskops.py +0 -45
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/constants.py +2 -2
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/core/directory.py +2 -2
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/native/diskops_handler.py +127 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/native/legacy/diskops.py +45 -0
- {flyshell-1.4.6 → flyshell-1.4.8/src/flyshell.egg-info}/PKG-INFO +1 -1
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell.egg-info/SOURCES.txt +4 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_diskops_ext.py +65 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_diskops_lgc.py +29 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_diskops_old.py +0 -23
- {flyshell-1.4.6 → flyshell-1.4.8}/LICENSE +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/MANIFEST.in +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/README.md +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/posix/cat.c +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/posix/dir.c +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/posix/mkdir.c +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/posix/touch.c +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/shared/dir_types.c +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/shared/dir_types.h +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/shared/native_errors.h +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/shared/win32_utf.h +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/win32/cat.c +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/win32/dir.c +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/win32/mkdir.c +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/c_src/diskops/win32/touch.c +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/pyproject.toml +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/setup.cfg +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/__init__.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/abstract/__init__.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/abstract/base_cmd.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/abstract/base_plugin.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/abstract/parent_cmd.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/accounts/__init__.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/accounts/auth.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/bin/__init__.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/builtin/__init__.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/builtin/fs.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/builtin/pkg.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/builtin/system.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/builtin/utils.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/core/__init__.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/core/console.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/core/data.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/main.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/native/__init__.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/native/diskops_bridge.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/native/legacy/__init__.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/startup/__init__.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/startup/deps.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/startup/env.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell/startup/loader.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell.egg-info/dependency_links.txt +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell.egg-info/entry_points.txt +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell.egg-info/requires.txt +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/src/flyshell.egg-info/top_level.txt +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_auth.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_data.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_deps.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_directory.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_env.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_fs.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_loader.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_pkg.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_security.py +0 -0
- {flyshell-1.4.6 → flyshell-1.4.8}/tests/test_utils.py +0 -0
|
@@ -13,6 +13,10 @@ Result list_dir(const char *path, DirList *out_list);
|
|
|
13
13
|
|
|
14
14
|
Result make_dir(const char *path, bool parents);
|
|
15
15
|
|
|
16
|
+
Result rename_item(const char *src, const char *dst);
|
|
17
|
+
|
|
18
|
+
Result remove_dir(const char *path, bool force);
|
|
19
|
+
|
|
16
20
|
static PyObject *method_ping(PyObject *self, PyObject *args) {
|
|
17
21
|
return PyLong_FromLong(42);
|
|
18
22
|
}
|
|
@@ -99,12 +103,36 @@ static PyObject *method_mkdir(PyObject *self, PyObject *args) {
|
|
|
99
103
|
return Py_BuildValue("(is)", (int)res, "");
|
|
100
104
|
}
|
|
101
105
|
|
|
106
|
+
static PyObject *method_rename(PyObject *self, PyObject *args) {
|
|
107
|
+
const char *src;
|
|
108
|
+
const char *dst;
|
|
109
|
+
if (!PyArg_ParseTuple(args, "ss", &src, &dst)) {
|
|
110
|
+
return NULL;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
Result res = rename_item(src, dst);
|
|
114
|
+
return Py_BuildValue("(is)", (int)res, "");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static PyObject *method_rmdir(PyObject *self, PyObject *args) {
|
|
118
|
+
const char *path;
|
|
119
|
+
int force = 0;
|
|
120
|
+
if (!PyArg_ParseTuple(args, "s|p", &path, &force)) {
|
|
121
|
+
return NULL;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
Result res = remove_dir(path, force != 0);
|
|
125
|
+
return Py_BuildValue("(is)", (int)res, "");
|
|
126
|
+
}
|
|
127
|
+
|
|
102
128
|
static PyMethodDef DiskopsMethods[] = {
|
|
103
129
|
{"ping", method_ping, METH_NOARGS, "Health check ping."},
|
|
104
130
|
{"cat", method_cat, METH_VARARGS, "Read file content natively."},
|
|
105
131
|
{"touch", method_touch, METH_VARARGS, "Touch or create file natively."},
|
|
106
132
|
{"dir", method_dir, METH_VARARGS, "List directory contents natively."},
|
|
107
133
|
{"mkdir", method_mkdir, METH_VARARGS, "Create directory natively."},
|
|
134
|
+
{"rename", method_rename, METH_VARARGS, "Rename file or directory natively."},
|
|
135
|
+
{"rmdir", method_rmdir, METH_VARARGS, "Remove directory natively."},
|
|
108
136
|
{NULL, NULL, 0, NULL},
|
|
109
137
|
};
|
|
110
138
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// c_src/diskops/posix/rename.c
|
|
2
|
+
|
|
3
|
+
#include "../shared/native_errors.h"
|
|
4
|
+
#include <errno.h>
|
|
5
|
+
#include <stdio.h>
|
|
6
|
+
#include <sys/stat.h>
|
|
7
|
+
|
|
8
|
+
Result rename_item(const char *src, const char *dst) {
|
|
9
|
+
if (!src || src[0] == '\0' || !dst || dst[0] == '\0') {
|
|
10
|
+
return ERR_INVALID_PATH;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
struct stat src_st;
|
|
14
|
+
if (lstat(src, &src_st) != 0) {
|
|
15
|
+
return map_posix_errno(errno);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
struct stat dst_st;
|
|
19
|
+
if (lstat(dst, &dst_st) == 0) {
|
|
20
|
+
if (src_st.st_dev == dst_st.st_dev && src_st.st_ino == dst_st.st_ino) {
|
|
21
|
+
return ERR_SAME_FILE;
|
|
22
|
+
}
|
|
23
|
+
return ERR_EXISTS;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (rename(src, dst) != 0) {
|
|
27
|
+
return map_posix_errno(errno);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return SUCCESS;
|
|
31
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// c_src/diskops/posix/rmdir.c
|
|
2
|
+
|
|
3
|
+
#define _POSIX_C_SOURCE 200809L
|
|
4
|
+
#define _GNU_SOURCE
|
|
5
|
+
|
|
6
|
+
#include "../shared/native_errors.h"
|
|
7
|
+
#include <dirent.h>
|
|
8
|
+
#include <errno.h>
|
|
9
|
+
#include <stdbool.h>
|
|
10
|
+
#include <stdio.h>
|
|
11
|
+
#include <stdlib.h>
|
|
12
|
+
#include <string.h>
|
|
13
|
+
#include <sys/stat.h>
|
|
14
|
+
#include <unistd.h>
|
|
15
|
+
|
|
16
|
+
static Result remove_dir_recursive_posix(const char *path) {
|
|
17
|
+
DIR *dir = opendir(path);
|
|
18
|
+
if (!dir) {
|
|
19
|
+
return map_posix_errno(errno);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
size_t base_len = strlen(path);
|
|
23
|
+
bool has_slash = (base_len > 0 && path[base_len - 1] == '/') != 0;
|
|
24
|
+
|
|
25
|
+
struct dirent *entry;
|
|
26
|
+
while ((entry = readdir(dir)) != NULL) {
|
|
27
|
+
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
size_t name_len = strlen(entry->d_name);
|
|
32
|
+
size_t child_len = base_len + (has_slash ? 0 : 1) + name_len + 1;
|
|
33
|
+
char *child_path = (char *)malloc(child_len);
|
|
34
|
+
if (!child_path) {
|
|
35
|
+
closedir(dir);
|
|
36
|
+
return ERR_IO;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (has_slash) {
|
|
40
|
+
snprintf(child_path, child_len, "%s%s", path, entry->d_name);
|
|
41
|
+
} else {
|
|
42
|
+
snprintf(child_path, child_len, "%s/%s", path, entry->d_name);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
struct stat st;
|
|
46
|
+
if (lstat(child_path, &st) != 0) {
|
|
47
|
+
int err = errno;
|
|
48
|
+
free(child_path);
|
|
49
|
+
closedir(dir);
|
|
50
|
+
return map_posix_errno(err);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Result child_res;
|
|
54
|
+
if (S_ISDIR(st.st_mode)) {
|
|
55
|
+
child_res = remove_dir_recursive_posix(child_path);
|
|
56
|
+
} else {
|
|
57
|
+
child_res = (unlink(child_path) == 0) ? SUCCESS : map_posix_errno(errno);
|
|
58
|
+
}
|
|
59
|
+
free(child_path);
|
|
60
|
+
|
|
61
|
+
if (child_res != SUCCESS) {
|
|
62
|
+
closedir(dir);
|
|
63
|
+
return child_res;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
closedir(dir);
|
|
68
|
+
if (rmdir(path) != 0) {
|
|
69
|
+
return map_posix_errno(errno);
|
|
70
|
+
}
|
|
71
|
+
return SUCCESS;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
Result remove_dir(const char *path, bool force) {
|
|
75
|
+
if (!path || path[0] == '\0') {
|
|
76
|
+
return ERR_INVALID_PATH;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
struct stat st;
|
|
80
|
+
if (lstat(path, &st) != 0) {
|
|
81
|
+
return map_posix_errno(errno);
|
|
82
|
+
}
|
|
83
|
+
if (!S_ISDIR(st.st_mode)) {
|
|
84
|
+
return ERR_NOT_DIR;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!force) {
|
|
88
|
+
if (rmdir(path) != 0) {
|
|
89
|
+
if (errno == EEXIST || errno == ENOTEMPTY) {
|
|
90
|
+
return ERR_NOT_EMPTY;
|
|
91
|
+
}
|
|
92
|
+
return map_posix_errno(errno);
|
|
93
|
+
}
|
|
94
|
+
return SUCCESS;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return remove_dir_recursive_posix(path);
|
|
98
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// c_src/diskops/win32/rename.c
|
|
2
|
+
|
|
3
|
+
#include "../shared/native_errors.h"
|
|
4
|
+
#include "../shared/win32_utf.h"
|
|
5
|
+
#include <stdlib.h>
|
|
6
|
+
#include <windows.h>
|
|
7
|
+
|
|
8
|
+
Result rename_item(const char *src, const char *dst) {
|
|
9
|
+
if (!src || src[0] == '\0' || !dst || dst[0] == '\0') {
|
|
10
|
+
return ERR_INVALID_PATH;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
wchar_t *wsrc = utf8_to_wide(src);
|
|
14
|
+
if (!wsrc) {
|
|
15
|
+
return ERR_INVALID_PATH;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
wchar_t *wdst = utf8_to_wide(dst);
|
|
19
|
+
if (!wdst) {
|
|
20
|
+
free(wsrc);
|
|
21
|
+
return ERR_INVALID_PATH;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (_wcsicmp(wsrc, wdst) == 0 && wcscmp(wsrc, wdst) == 0) {
|
|
25
|
+
free(wsrc);
|
|
26
|
+
free(wdst);
|
|
27
|
+
return ERR_SAME_FILE;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
DWORD dst_attrs = GetFileAttributesW(wdst);
|
|
31
|
+
if (dst_attrs != INVALID_FILE_ATTRIBUTES) {
|
|
32
|
+
free(wsrc);
|
|
33
|
+
free(wdst);
|
|
34
|
+
return ERR_EXISTS;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (MoveFileW(wsrc, wdst) == 0) {
|
|
38
|
+
DWORD err = GetLastError();
|
|
39
|
+
free(wsrc);
|
|
40
|
+
free(wdst);
|
|
41
|
+
return map_win32_error(err);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
free(wsrc);
|
|
45
|
+
free(wdst);
|
|
46
|
+
return SUCCESS;
|
|
47
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// c_src/diskops/win32/rmdir.c
|
|
2
|
+
|
|
3
|
+
#include "../shared/native_errors.h"
|
|
4
|
+
#include "../shared/win32_utf.h"
|
|
5
|
+
#include <stdbool.h>
|
|
6
|
+
#include <stdlib.h>
|
|
7
|
+
#include <string.h>
|
|
8
|
+
#include <windows.h>
|
|
9
|
+
|
|
10
|
+
static Result remove_dir_recursive_win32(const wchar_t *wpath) {
|
|
11
|
+
size_t wlen = wcslen(wpath);
|
|
12
|
+
bool has_sep = (wlen > 0 && (wpath[wlen - 1] == L'\\' || wpath[wlen - 1] == L'/')) != 0;
|
|
13
|
+
size_t pat_len = wlen + (has_sep ? 1 : 2) + 1;
|
|
14
|
+
|
|
15
|
+
wchar_t *wpattern = (wchar_t *)malloc(pat_len * sizeof(wchar_t));
|
|
16
|
+
if (!wpattern) {
|
|
17
|
+
return ERR_IO;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
memcpy(wpattern, wpath, wlen * sizeof(wchar_t));
|
|
21
|
+
size_t pos = wlen;
|
|
22
|
+
if (!has_sep) {
|
|
23
|
+
wpattern[pos++] = L'\\';
|
|
24
|
+
}
|
|
25
|
+
wpattern[pos++] = L'*';
|
|
26
|
+
wpattern[pos] = L'\0';
|
|
27
|
+
|
|
28
|
+
WIN32_FIND_DATAW find_data;
|
|
29
|
+
HANDLE h_find = FindFirstFileW(wpattern, &find_data);
|
|
30
|
+
DWORD find_err = GetLastError();
|
|
31
|
+
free(wpattern);
|
|
32
|
+
|
|
33
|
+
if (h_find == INVALID_HANDLE_VALUE) {
|
|
34
|
+
return map_win32_error(find_err);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
do {
|
|
38
|
+
if (wcscmp(find_data.cFileName, L".") == 0 || wcscmp(find_data.cFileName, L"..") == 0) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
size_t name_len = wcslen(find_data.cFileName);
|
|
43
|
+
size_t child_len = wlen + (has_sep ? 0 : 1) + name_len + 1;
|
|
44
|
+
wchar_t *wchild = (wchar_t *)malloc(child_len * sizeof(wchar_t));
|
|
45
|
+
if (!wchild) {
|
|
46
|
+
FindClose(h_find);
|
|
47
|
+
return ERR_IO;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
memcpy(wchild, wpath, wlen * sizeof(wchar_t));
|
|
51
|
+
size_t cpos = wlen;
|
|
52
|
+
if (!has_sep) {
|
|
53
|
+
wchild[cpos++] = L'\\';
|
|
54
|
+
}
|
|
55
|
+
memcpy(wchild + cpos, find_data.cFileName, (name_len + 1) * sizeof(wchar_t));
|
|
56
|
+
|
|
57
|
+
bool is_dir = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
|
58
|
+
bool is_reparse = (find_data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
|
|
59
|
+
|
|
60
|
+
if ((find_data.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0) {
|
|
61
|
+
SetFileAttributesW(wchild, find_data.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Result child_res;
|
|
65
|
+
if (is_dir && !is_reparse) {
|
|
66
|
+
child_res = remove_dir_recursive_win32(wchild);
|
|
67
|
+
} else if (is_dir) {
|
|
68
|
+
child_res = (RemoveDirectoryW(wchild) != 0) ? SUCCESS : map_win32_error(GetLastError());
|
|
69
|
+
} else {
|
|
70
|
+
child_res = (DeleteFileW(wchild) != 0) ? SUCCESS : map_win32_error(GetLastError());
|
|
71
|
+
}
|
|
72
|
+
free(wchild);
|
|
73
|
+
|
|
74
|
+
if (child_res != SUCCESS) {
|
|
75
|
+
FindClose(h_find);
|
|
76
|
+
return child_res;
|
|
77
|
+
}
|
|
78
|
+
} while (FindNextFileW(h_find, &find_data) != 0);
|
|
79
|
+
|
|
80
|
+
DWORD loop_err = GetLastError();
|
|
81
|
+
FindClose(h_find);
|
|
82
|
+
|
|
83
|
+
if (loop_err != ERROR_NO_MORE_FILES && loop_err != ERROR_SUCCESS) {
|
|
84
|
+
return map_win32_error(loop_err);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (RemoveDirectoryW(wpath) == 0) {
|
|
88
|
+
return map_win32_error(GetLastError());
|
|
89
|
+
}
|
|
90
|
+
return SUCCESS;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
Result remove_dir(const char *path, bool force) {
|
|
94
|
+
if (!path || path[0] == '\0') {
|
|
95
|
+
return ERR_INVALID_PATH;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
wchar_t *wpath = utf8_to_wide(path);
|
|
99
|
+
if (!wpath) {
|
|
100
|
+
return ERR_INVALID_PATH;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
DWORD attrs = GetFileAttributesW(wpath);
|
|
104
|
+
if (attrs == INVALID_FILE_ATTRIBUTES) {
|
|
105
|
+
DWORD err = GetLastError();
|
|
106
|
+
free(wpath);
|
|
107
|
+
return map_win32_error(err);
|
|
108
|
+
}
|
|
109
|
+
if ((attrs & FILE_ATTRIBUTE_DIRECTORY) == 0) {
|
|
110
|
+
free(wpath);
|
|
111
|
+
return ERR_NOT_DIR;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!force) {
|
|
115
|
+
BOOL ok = RemoveDirectoryW(wpath);
|
|
116
|
+
DWORD err = GetLastError();
|
|
117
|
+
free(wpath);
|
|
118
|
+
if (ok == 0) {
|
|
119
|
+
return map_win32_error(err);
|
|
120
|
+
}
|
|
121
|
+
return SUCCESS;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if ((attrs & FILE_ATTRIBUTE_READONLY) != 0) {
|
|
125
|
+
SetFileAttributesW(wpath, attrs & ~FILE_ATTRIBUTE_READONLY);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
Result res = remove_dir_recursive_win32(wpath);
|
|
129
|
+
free(wpath);
|
|
130
|
+
return res;
|
|
131
|
+
}
|
|
@@ -12,11 +12,15 @@ if sys.platform == "win32":
|
|
|
12
12
|
sources.append("c_src/diskops/win32/cat.c")
|
|
13
13
|
sources.append("c_src/diskops/win32/dir.c")
|
|
14
14
|
sources.append("c_src/diskops/win32/mkdir.c")
|
|
15
|
+
sources.append("c_src/diskops/win32/rename.c")
|
|
16
|
+
sources.append("c_src/diskops/win32/rmdir.c")
|
|
15
17
|
sources.append("c_src/diskops/win32/touch.c")
|
|
16
18
|
else:
|
|
17
19
|
sources.append("c_src/diskops/posix/cat.c")
|
|
18
20
|
sources.append("c_src/diskops/posix/dir.c")
|
|
19
21
|
sources.append("c_src/diskops/posix/mkdir.c")
|
|
22
|
+
sources.append("c_src/diskops/posix/rename.c")
|
|
23
|
+
sources.append("c_src/diskops/posix/rmdir.c")
|
|
20
24
|
sources.append("c_src/diskops/posix/touch.c")
|
|
21
25
|
|
|
22
26
|
native_diskops = Extension(
|
|
@@ -141,51 +141,6 @@ class Move(BaseCmd):
|
|
|
141
141
|
return (1, f"\nSystem Error: Failed to move '{raw_src}' ({e})\n")
|
|
142
142
|
|
|
143
143
|
|
|
144
|
-
class Rename(BaseCmd):
|
|
145
|
-
name = "rename"
|
|
146
|
-
description = "Rename a file or directory"
|
|
147
|
-
min_args = 2
|
|
148
|
-
options = "Old name, then new name"
|
|
149
|
-
aliases = []
|
|
150
|
-
|
|
151
|
-
def execute(self, args):
|
|
152
|
-
raw_src = args[0].strip("\"'")
|
|
153
|
-
raw_new_name = args[1].strip("\"'")
|
|
154
|
-
if raw_new_name in (".", "..") or "/" in raw_new_name or "\\" in raw_new_name:
|
|
155
|
-
return (1, "\nCommand Error: Invalid file name.\n")
|
|
156
|
-
src_path = Path(raw_src).expanduser().resolve()
|
|
157
|
-
if not src_path.exists():
|
|
158
|
-
return (1, f"\nSystem Error: Target '{raw_src}' not found.\n")
|
|
159
|
-
flyshell_dirs = [
|
|
160
|
-
c.APP_DIR.resolve(),
|
|
161
|
-
c.PACKAGE_ROOT.resolve(),
|
|
162
|
-
c.PROJECT_ROOT.resolve(),
|
|
163
|
-
]
|
|
164
|
-
for protected in flyshell_dirs:
|
|
165
|
-
if src_path == protected or src_path.is_relative_to(protected):
|
|
166
|
-
return (
|
|
167
|
-
1,
|
|
168
|
-
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
169
|
-
f"Target '{raw_src}' contains or belongs to Flyshell system files.\n",
|
|
170
|
-
)
|
|
171
|
-
new_path = src_path.parent / raw_new_name
|
|
172
|
-
if new_path.exists():
|
|
173
|
-
return (
|
|
174
|
-
1,
|
|
175
|
-
f"\nSystem Error: An item named '{raw_new_name}' already exists in this folder.\n",
|
|
176
|
-
)
|
|
177
|
-
try:
|
|
178
|
-
src_path.rename(new_path)
|
|
179
|
-
return (0, f"\nSUCCESS! Renamed '{src_path.name}' -> '{new_path.name}'\n")
|
|
180
|
-
except PermissionError:
|
|
181
|
-
return (
|
|
182
|
-
1,
|
|
183
|
-
f"\nSystem Error: Permission denied. Cannot rename '{raw_src}'\n",
|
|
184
|
-
)
|
|
185
|
-
except Exception as e:
|
|
186
|
-
return (1, f"\nSystem Error: Failed to rename '{raw_src}' ({e})\n")
|
|
187
|
-
|
|
188
|
-
|
|
189
144
|
class Rm(BaseCmd):
|
|
190
145
|
name = "rm"
|
|
191
146
|
description = "Remove files from the filesystem"
|
|
@@ -70,9 +70,9 @@ INSTALLED_COMMANDS: list[BaseCmd] = [
|
|
|
70
70
|
system.OpenFile(),
|
|
71
71
|
pkg.Pkg(),
|
|
72
72
|
utils.Reboot(),
|
|
73
|
-
|
|
73
|
+
diskops.Rename(),
|
|
74
74
|
diskops_legacy.Rm(),
|
|
75
|
-
|
|
75
|
+
diskops.RmDir(),
|
|
76
76
|
utils.Sleep(),
|
|
77
77
|
system.SysExe(),
|
|
78
78
|
diskops.Touch(),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# src/flyshell/native/diskops_handler.py
|
|
2
2
|
|
|
3
|
+
from flyshell import constants as c
|
|
3
4
|
from flyshell.abstract.base_cmd import BaseCmd
|
|
4
5
|
from flyshell.native import diskops_bridge as bridge
|
|
5
6
|
from flyshell.native.legacy import diskops as legacy
|
|
@@ -118,6 +119,132 @@ class MkDir(BaseCmd):
|
|
|
118
119
|
return (0, f"\nSUCCESS! Created directory '{raw_target}'\n")
|
|
119
120
|
|
|
120
121
|
|
|
122
|
+
class Rename(BaseCmd):
|
|
123
|
+
name = "rename"
|
|
124
|
+
description = "Rename a file or directory"
|
|
125
|
+
min_args = 2
|
|
126
|
+
options = "Old name, then new name"
|
|
127
|
+
aliases = []
|
|
128
|
+
|
|
129
|
+
def execute(self, args):
|
|
130
|
+
raw_src = args[0].strip("\"'")
|
|
131
|
+
raw_new_name = args[1].strip("\"'")
|
|
132
|
+
if raw_new_name in (".", "..") or "/" in raw_new_name or "\\" in raw_new_name:
|
|
133
|
+
return (1, "\nCommand Error: Invalid file name.\n")
|
|
134
|
+
src_path = Path(raw_src).expanduser().resolve()
|
|
135
|
+
if not src_path.exists():
|
|
136
|
+
return (1, f"\nSystem Error: Target '{raw_src}' not found.\n")
|
|
137
|
+
flyshell_dirs = [
|
|
138
|
+
c.APP_DIR.resolve(),
|
|
139
|
+
c.PACKAGE_ROOT.resolve(),
|
|
140
|
+
c.PROJECT_ROOT.resolve(),
|
|
141
|
+
]
|
|
142
|
+
for protected in flyshell_dirs:
|
|
143
|
+
if src_path == protected or src_path.is_relative_to(protected):
|
|
144
|
+
return (
|
|
145
|
+
1,
|
|
146
|
+
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
147
|
+
f"Target '{raw_src}' contains or belongs to Flyshell system files.\n",
|
|
148
|
+
)
|
|
149
|
+
new_path = src_path.parent / raw_new_name
|
|
150
|
+
if new_path.exists():
|
|
151
|
+
return (
|
|
152
|
+
1,
|
|
153
|
+
f"\nSystem Error: An item named '{raw_new_name}' already exists in this folder.\n",
|
|
154
|
+
)
|
|
155
|
+
if bridge.has_native_support() and hasattr(bridge._native, "rename"):
|
|
156
|
+
code, _ = bridge._native.rename(str(src_path), str(new_path))
|
|
157
|
+
else:
|
|
158
|
+
code, _ = legacy.lgc_rename(src_path, new_path)
|
|
159
|
+
if code != 0:
|
|
160
|
+
return bridge.translate_error(code, raw_src)
|
|
161
|
+
return (0, f"\nSUCCESS! Renamed '{src_path.name}' -> '{new_path.name}'\n")
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
class RmDir(BaseCmd):
|
|
165
|
+
name = "rmdir"
|
|
166
|
+
description = "Remove the specified directory"
|
|
167
|
+
min_args = 1
|
|
168
|
+
options = "Target directory"
|
|
169
|
+
aliases = []
|
|
170
|
+
|
|
171
|
+
def execute(self, args):
|
|
172
|
+
force = ("-f" in args) or ("--force" in args)
|
|
173
|
+
path_tokens = [arg for arg in args if arg not in ("-f", "--force")]
|
|
174
|
+
if not path_tokens:
|
|
175
|
+
return (1, "\nCommand Error: Target directory not specified.\n")
|
|
176
|
+
raw_target = " ".join(path_tokens).strip("\"'")
|
|
177
|
+
target_path = Path(raw_target).expanduser().resolve()
|
|
178
|
+
if not target_path.exists():
|
|
179
|
+
return (1, f"\nSystem Error: Target '{raw_target}' not found.\n")
|
|
180
|
+
if target_path == target_path.parent or str(target_path) == target_path.anchor:
|
|
181
|
+
return (
|
|
182
|
+
1,
|
|
183
|
+
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
184
|
+
"You cannot delete the root filesystem directory.\n",
|
|
185
|
+
)
|
|
186
|
+
critical_system_dirs = [
|
|
187
|
+
Path.home().parent.resolve(),
|
|
188
|
+
Path.home().resolve(),
|
|
189
|
+
]
|
|
190
|
+
if c.HOST_OS == "Windows":
|
|
191
|
+
system_drive = os.environ.get("SystemDrive", "C:")
|
|
192
|
+
critical_system_dirs.extend(
|
|
193
|
+
[
|
|
194
|
+
Path(f"{system_drive}\\Windows").resolve(),
|
|
195
|
+
Path(f"{system_drive}\\Program Files").resolve(),
|
|
196
|
+
Path(f"{system_drive}\\Program Files (x86)").resolve(),
|
|
197
|
+
]
|
|
198
|
+
)
|
|
199
|
+
else:
|
|
200
|
+
critical_system_dirs.extend(
|
|
201
|
+
[
|
|
202
|
+
Path("/bin").resolve(),
|
|
203
|
+
Path("/etc").resolve(),
|
|
204
|
+
Path("/usr").resolve(),
|
|
205
|
+
Path("/var").resolve(),
|
|
206
|
+
]
|
|
207
|
+
)
|
|
208
|
+
if target_path in critical_system_dirs:
|
|
209
|
+
return (
|
|
210
|
+
1,
|
|
211
|
+
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
212
|
+
f"Target '{raw_target}' is a protected operating system directory.\n",
|
|
213
|
+
)
|
|
214
|
+
if target_path == Path(os.getcwd()).resolve():
|
|
215
|
+
return (
|
|
216
|
+
1,
|
|
217
|
+
"\nSystem Error: Cannot remove current working directory.\n"
|
|
218
|
+
"Switch to a different directory using 'cd' first.\n",
|
|
219
|
+
)
|
|
220
|
+
flyshell_dirs = [
|
|
221
|
+
c.APP_DIR.resolve(),
|
|
222
|
+
c.PACKAGE_ROOT.resolve(),
|
|
223
|
+
c.PROJECT_ROOT.resolve(),
|
|
224
|
+
]
|
|
225
|
+
for protected in flyshell_dirs:
|
|
226
|
+
if target_path == protected or target_path.is_relative_to(protected):
|
|
227
|
+
return (
|
|
228
|
+
1,
|
|
229
|
+
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
230
|
+
f"Target '{raw_target}' contains or belongs to Flyshell system files.\n"
|
|
231
|
+
"If you wish to delete Flyshell, use the host.\n",
|
|
232
|
+
)
|
|
233
|
+
if bridge.has_native_support() and hasattr(bridge._native, "rmdir"):
|
|
234
|
+
code, _ = bridge._native.rmdir(str(target_path), force)
|
|
235
|
+
else:
|
|
236
|
+
code, _ = legacy.lgc_rmdir(target_path, force)
|
|
237
|
+
if code != 0:
|
|
238
|
+
if code == -6 and not force:
|
|
239
|
+
return (
|
|
240
|
+
1,
|
|
241
|
+
f"\nDirectory Error: Directory '{raw_target}' is not empty.\n"
|
|
242
|
+
"Use '-f' or '--force' to remove a non-empty directory and its contents.\n",
|
|
243
|
+
)
|
|
244
|
+
return bridge.translate_error(code, raw_target)
|
|
245
|
+
return (0, f"\nSUCCESS! Removed directory '{raw_target}'\n")
|
|
246
|
+
|
|
247
|
+
|
|
121
248
|
class Touch(BaseCmd):
|
|
122
249
|
name = "touch"
|
|
123
250
|
description = "Create an empty file or update existing file timestamps"
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
import os
|
|
5
|
+
import shutil
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
def lgc_cat(target_path: Path) -> tuple[int, str]:
|
|
@@ -73,6 +74,50 @@ def lgc_mkdir(target_path: Path, parents: bool = False) -> tuple[int, str]:
|
|
|
73
74
|
return (-99, "") # ERR_UNKNOWN
|
|
74
75
|
|
|
75
76
|
|
|
77
|
+
def lgc_rename(src_path: Path, dst_path: Path) -> tuple[int, str]:
|
|
78
|
+
if not src_path.exists():
|
|
79
|
+
return (-1, "") # ERR_NOT_FOUND
|
|
80
|
+
if src_path == dst_path:
|
|
81
|
+
return (-7, "") # ERR_SAME_FILE
|
|
82
|
+
if dst_path.exists():
|
|
83
|
+
return (-5, "") # ERR_EXISTS
|
|
84
|
+
try:
|
|
85
|
+
src_path.rename(dst_path)
|
|
86
|
+
return (0, "") # SUCCESS
|
|
87
|
+
except PermissionError:
|
|
88
|
+
return (-2, "") # ERR_PERMISSION
|
|
89
|
+
except OSError as e:
|
|
90
|
+
if getattr(e, "errno", None) == 18:
|
|
91
|
+
return (-10, "") # ERR_XDEV
|
|
92
|
+
return (-13, "") # ERR_IO
|
|
93
|
+
except Exception:
|
|
94
|
+
return (-99, "") # ERR_UNKNOWN
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def lgc_rmdir(target_path: Path, force: bool = False) -> tuple[int, str]:
|
|
98
|
+
if not target_path.exists():
|
|
99
|
+
return (-1, "") # ERR_NOT_FOUND
|
|
100
|
+
if not target_path.is_dir():
|
|
101
|
+
return (-4, "") # ERR_NOT_DIR
|
|
102
|
+
try:
|
|
103
|
+
has_contents = any(target_path.iterdir())
|
|
104
|
+
if has_contents and not force:
|
|
105
|
+
return (-6, "") # ERR_NOT_EMPTY
|
|
106
|
+
if has_contents and force:
|
|
107
|
+
shutil.rmtree(target_path)
|
|
108
|
+
else:
|
|
109
|
+
os.rmdir(target_path)
|
|
110
|
+
return (0, "") # SUCCESS
|
|
111
|
+
except PermissionError:
|
|
112
|
+
return (-2, "") # ERR_PERMISSION
|
|
113
|
+
except OSError as e:
|
|
114
|
+
if getattr(e, "errno", None) in (39, 66, 145):
|
|
115
|
+
return (-6, "") # ERR_NOT_EMPTY
|
|
116
|
+
return (-13, "") # ERR_IO
|
|
117
|
+
except Exception:
|
|
118
|
+
return (-99, "") # ERR_UNKNOWN
|
|
119
|
+
|
|
120
|
+
|
|
76
121
|
def lgc_touch(target_path: Path) -> tuple[int, str]:
|
|
77
122
|
if target_path.is_dir():
|
|
78
123
|
return (-3, "") # ERR_IS_DIR
|
|
@@ -7,6 +7,8 @@ c_src/diskops/diskops.c
|
|
|
7
7
|
c_src/diskops/posix/cat.c
|
|
8
8
|
c_src/diskops/posix/dir.c
|
|
9
9
|
c_src/diskops/posix/mkdir.c
|
|
10
|
+
c_src/diskops/posix/rename.c
|
|
11
|
+
c_src/diskops/posix/rmdir.c
|
|
10
12
|
c_src/diskops/posix/touch.c
|
|
11
13
|
c_src/diskops/shared/dir_types.c
|
|
12
14
|
c_src/diskops/shared/dir_types.h
|
|
@@ -15,6 +17,8 @@ c_src/diskops/shared/win32_utf.h
|
|
|
15
17
|
c_src/diskops/win32/cat.c
|
|
16
18
|
c_src/diskops/win32/dir.c
|
|
17
19
|
c_src/diskops/win32/mkdir.c
|
|
20
|
+
c_src/diskops/win32/rename.c
|
|
21
|
+
c_src/diskops/win32/rmdir.c
|
|
18
22
|
c_src/diskops/win32/touch.c
|
|
19
23
|
src/flyshell/__init__.py
|
|
20
24
|
src/flyshell/constants.py
|
|
@@ -11,6 +11,38 @@ def test_native_extension_loaded():
|
|
|
11
11
|
assert bridge._native.ping() == 42
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
def test_native_rmdir_empty_and_force(tmp_path):
|
|
15
|
+
cmd = handler.RmDir()
|
|
16
|
+
empty_dir = tmp_path / "empty_folder"
|
|
17
|
+
empty_dir.mkdir()
|
|
18
|
+
exit_code, msg = cmd.execute([str(empty_dir)])
|
|
19
|
+
assert exit_code == 0
|
|
20
|
+
assert "Removed directory" in msg
|
|
21
|
+
assert not empty_dir.exists()
|
|
22
|
+
non_empty = tmp_path / "full_folder"
|
|
23
|
+
nested = non_empty / "sub_folder"
|
|
24
|
+
nested.mkdir(parents=True)
|
|
25
|
+
(nested / "item.txt").write_text("data", encoding="utf-8")
|
|
26
|
+
exit_code, msg = cmd.execute([str(non_empty)])
|
|
27
|
+
assert exit_code == 1
|
|
28
|
+
assert "not empty" in msg
|
|
29
|
+
assert non_empty.exists()
|
|
30
|
+
exit_code, msg = cmd.execute(["-f", str(non_empty)])
|
|
31
|
+
assert exit_code == 0
|
|
32
|
+
assert not non_empty.exists()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_native_rmdir_errors(tmp_path):
|
|
36
|
+
regular_file = tmp_path / "not_a_dir.txt"
|
|
37
|
+
regular_file.write_text("hello", encoding="utf-8")
|
|
38
|
+
code, _ = bridge._native.rmdir(str(regular_file), False)
|
|
39
|
+
assert code == -4 # ERR_NOT_DIR
|
|
40
|
+
cmd = handler.RmDir()
|
|
41
|
+
exit_code, msg = cmd.execute([str(tmp_path / "missing_folder")])
|
|
42
|
+
assert exit_code == 1
|
|
43
|
+
assert "not found" in msg
|
|
44
|
+
|
|
45
|
+
|
|
14
46
|
def test_native_cat_reads_and_formats_content(tmp_path):
|
|
15
47
|
file_path = tmp_path / "native_cat.txt"
|
|
16
48
|
file_path.write_text("alpha\nbeta\ngamma\ndelta\n", encoding="utf-8")
|
|
@@ -114,6 +146,39 @@ def test_native_touch_errors(tmp_path):
|
|
|
114
146
|
assert "Target is a directory, not a file" in msg
|
|
115
147
|
|
|
116
148
|
|
|
149
|
+
def test_native_rename_file_and_directory(tmp_path):
|
|
150
|
+
src = tmp_path / "old_name.txt"
|
|
151
|
+
src.write_text("payload", encoding="utf-8")
|
|
152
|
+
cmd = handler.Rename()
|
|
153
|
+
exit_code, msg = cmd.execute([str(src), "new_name.txt"])
|
|
154
|
+
assert exit_code == 0
|
|
155
|
+
assert "Renamed 'old_name.txt' -> 'new_name.txt'" in msg
|
|
156
|
+
assert not src.exists()
|
|
157
|
+
assert (tmp_path / "new_name.txt").read_text(encoding="utf-8") == "payload"
|
|
158
|
+
src_dir = tmp_path / "old_dir"
|
|
159
|
+
src_dir.mkdir()
|
|
160
|
+
exit_code, msg = cmd.execute([str(src_dir), "new_dir"])
|
|
161
|
+
assert exit_code == 0
|
|
162
|
+
assert not src_dir.exists()
|
|
163
|
+
assert (tmp_path / "new_dir").is_dir()
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def test_native_rename_errors(tmp_path):
|
|
167
|
+
cmd = handler.Rename()
|
|
168
|
+
exit_code, msg = cmd.execute([str(tmp_path / "ghost.txt"), "other.txt"])
|
|
169
|
+
assert exit_code == 1
|
|
170
|
+
assert "not found" in msg
|
|
171
|
+
a = tmp_path / "a.txt"
|
|
172
|
+
b = tmp_path / "b.txt"
|
|
173
|
+
a.write_text("1", encoding="utf-8")
|
|
174
|
+
b.write_text("2", encoding="utf-8")
|
|
175
|
+
code, _ = bridge._native.rename(str(a), str(b))
|
|
176
|
+
assert code == -5 # ERR_EXISTS
|
|
177
|
+
exit_code, msg = cmd.execute([str(a), "../escape.txt"])
|
|
178
|
+
assert exit_code == 1
|
|
179
|
+
assert "Invalid file name" in msg
|
|
180
|
+
|
|
181
|
+
|
|
117
182
|
def test_native_unicode_paths(tmp_path):
|
|
118
183
|
unicode_dir = tmp_path / "dir_日本語"
|
|
119
184
|
code, _ = bridge._native.mkdir(str(unicode_dir), False)
|
|
@@ -12,6 +12,35 @@ def force_legacy_backend(monkeypatch):
|
|
|
12
12
|
monkeypatch.setattr(bridge, "has_native_support", lambda: False)
|
|
13
13
|
|
|
14
14
|
|
|
15
|
+
def test_legacy_rmdir_empty_and_force(tmp_path):
|
|
16
|
+
cmd = handler.RmDir()
|
|
17
|
+
non_empty = tmp_path / "legacy_full"
|
|
18
|
+
(non_empty / "child").mkdir(parents=True)
|
|
19
|
+
(non_empty / "child" / "file.txt").write_text("abc", encoding="utf-8")
|
|
20
|
+
exit_code, msg = cmd.execute([str(non_empty)])
|
|
21
|
+
assert exit_code == 1
|
|
22
|
+
assert "not empty" in msg
|
|
23
|
+
exit_code, msg = cmd.execute(["-f", str(non_empty)])
|
|
24
|
+
assert exit_code == 0
|
|
25
|
+
assert not non_empty.exists()
|
|
26
|
+
regular_file = tmp_path / "file.txt"
|
|
27
|
+
regular_file.write_text("x", encoding="utf-8")
|
|
28
|
+
code, _ = legacy.lgc_rmdir(regular_file, force=False)
|
|
29
|
+
assert code == -4 # ERR_NOT_DIR
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_legacy_rename_file_and_errors(tmp_path):
|
|
33
|
+
src = tmp_path / "legacy_old.txt"
|
|
34
|
+
src.write_text("hello", encoding="utf-8")
|
|
35
|
+
cmd = handler.Rename()
|
|
36
|
+
exit_code, msg = cmd.execute([str(src), "legacy_new.txt"])
|
|
37
|
+
assert exit_code == 0
|
|
38
|
+
assert not src.exists()
|
|
39
|
+
assert (tmp_path / "legacy_new.txt").exists()
|
|
40
|
+
code, _ = legacy.lgc_rename(tmp_path / "missing.txt", tmp_path / "dst.txt")
|
|
41
|
+
assert code == -1 # ERR_NOT_FOUND
|
|
42
|
+
|
|
43
|
+
|
|
15
44
|
def test_legacy_cat_reads_content_with_limit_and_numbers(tmp_path):
|
|
16
45
|
file_path = tmp_path / "sample.txt"
|
|
17
46
|
file_path.write_text("line 1\nline 2\nline 3\nline 4\n", encoding="utf-8")
|
|
@@ -3,16 +3,6 @@
|
|
|
3
3
|
from flyshell.builtin import diskops
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
def test_rename_file(tmp_path):
|
|
7
|
-
src = tmp_path / "old.txt"
|
|
8
|
-
src.write_text("data")
|
|
9
|
-
cmd = diskops.Rename()
|
|
10
|
-
code, msg = cmd.execute([str(src), "new.txt"])
|
|
11
|
-
assert code == 0
|
|
12
|
-
assert not src.exists()
|
|
13
|
-
assert (tmp_path / "new.txt").exists()
|
|
14
|
-
|
|
15
|
-
|
|
16
6
|
def test_copy_file_and_directory(tmp_path):
|
|
17
7
|
src_file = tmp_path / "source.txt"
|
|
18
8
|
src_file.write_text("payload")
|
|
@@ -45,16 +35,3 @@ def test_rm_file_and_directory_recursive(tmp_path):
|
|
|
45
35
|
code, msg = cmd.execute(["-f", "-r", str(target_dir)])
|
|
46
36
|
assert code == 0
|
|
47
37
|
assert not target_dir.exists()
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def test_rmdir_empty_and_non_empty(tmp_path):
|
|
51
|
-
target_dir = tmp_path / "removable"
|
|
52
|
-
target_dir.mkdir()
|
|
53
|
-
cmd = diskops.RmDir()
|
|
54
|
-
(target_dir / "file.txt").write_text("data")
|
|
55
|
-
code, msg = cmd.execute([str(target_dir)])
|
|
56
|
-
assert code == 1
|
|
57
|
-
assert "not empty" in msg
|
|
58
|
-
code, msg = cmd.execute(["-f", str(target_dir)])
|
|
59
|
-
assert code == 0
|
|
60
|
-
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
|