flyshell 1.4.7__tar.gz → 1.4.9__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.7/src/flyshell.egg-info → flyshell-1.4.9}/PKG-INFO +1 -1
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/diskops.c +28 -0
- flyshell-1.4.9/c_src/diskops/posix/rm.c +33 -0
- flyshell-1.4.9/c_src/diskops/posix/rmdir.c +98 -0
- flyshell-1.4.9/c_src/diskops/win32/rm.c +52 -0
- flyshell-1.4.9/c_src/diskops/win32/rmdir.c +131 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/setup.py +4 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/constants.py +2 -2
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/core/directory.py +1 -1
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/native/diskops_handler.py +144 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/native/legacy/diskops.py +45 -0
- {flyshell-1.4.7 → flyshell-1.4.9/src/flyshell.egg-info}/PKG-INFO +1 -1
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell.egg-info/SOURCES.txt +4 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_diskops_ext.py +64 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_diskops_lgc.py +34 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_diskops_old.py +0 -13
- {flyshell-1.4.7 → flyshell-1.4.9}/LICENSE +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/MANIFEST.in +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/README.md +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/posix/cat.c +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/posix/dir.c +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/posix/mkdir.c +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/posix/rename.c +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/posix/touch.c +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/shared/dir_types.c +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/shared/dir_types.h +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/shared/native_errors.h +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/shared/win32_utf.h +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/win32/cat.c +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/win32/dir.c +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/win32/mkdir.c +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/win32/rename.c +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/c_src/diskops/win32/touch.c +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/pyproject.toml +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/setup.cfg +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/__init__.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/abstract/__init__.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/abstract/base_cmd.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/abstract/base_plugin.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/abstract/parent_cmd.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/accounts/__init__.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/accounts/auth.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/bin/__init__.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/builtin/__init__.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/builtin/diskops.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/builtin/fs.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/builtin/pkg.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/builtin/system.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/builtin/utils.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/core/__init__.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/core/console.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/core/data.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/main.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/native/__init__.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/native/diskops_bridge.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/native/legacy/__init__.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/startup/__init__.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/startup/deps.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/startup/env.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell/startup/loader.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell.egg-info/dependency_links.txt +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell.egg-info/entry_points.txt +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell.egg-info/requires.txt +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/src/flyshell.egg-info/top_level.txt +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_auth.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_data.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_deps.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_directory.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_env.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_fs.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_loader.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_pkg.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_security.py +0 -0
- {flyshell-1.4.7 → flyshell-1.4.9}/tests/test_utils.py +0 -0
|
@@ -15,6 +15,10 @@ Result make_dir(const char *path, bool parents);
|
|
|
15
15
|
|
|
16
16
|
Result rename_item(const char *src, const char *dst);
|
|
17
17
|
|
|
18
|
+
Result remove_dir(const char *path, bool force);
|
|
19
|
+
|
|
20
|
+
Result remove_item(const char *path, bool recursive);
|
|
21
|
+
|
|
18
22
|
static PyObject *method_ping(PyObject *self, PyObject *args) {
|
|
19
23
|
return PyLong_FromLong(42);
|
|
20
24
|
}
|
|
@@ -112,6 +116,28 @@ static PyObject *method_rename(PyObject *self, PyObject *args) {
|
|
|
112
116
|
return Py_BuildValue("(is)", (int)res, "");
|
|
113
117
|
}
|
|
114
118
|
|
|
119
|
+
static PyObject *method_rmdir(PyObject *self, PyObject *args) {
|
|
120
|
+
const char *path;
|
|
121
|
+
int force = 0;
|
|
122
|
+
if (!PyArg_ParseTuple(args, "s|p", &path, &force)) {
|
|
123
|
+
return NULL;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
Result res = remove_dir(path, force != 0);
|
|
127
|
+
return Py_BuildValue("(is)", (int)res, "");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static PyObject *method_rm(PyObject *self, PyObject *args) {
|
|
131
|
+
const char *path;
|
|
132
|
+
int recursive = 0;
|
|
133
|
+
if (!PyArg_ParseTuple(args, "s|p", &path, &recursive)) {
|
|
134
|
+
return NULL;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
Result res = remove_item(path, recursive != 0);
|
|
138
|
+
return Py_BuildValue("(is)", (int)res, "");
|
|
139
|
+
}
|
|
140
|
+
|
|
115
141
|
static PyMethodDef DiskopsMethods[] = {
|
|
116
142
|
{"ping", method_ping, METH_NOARGS, "Health check ping."},
|
|
117
143
|
{"cat", method_cat, METH_VARARGS, "Read file content natively."},
|
|
@@ -119,6 +145,8 @@ static PyMethodDef DiskopsMethods[] = {
|
|
|
119
145
|
{"dir", method_dir, METH_VARARGS, "List directory contents natively."},
|
|
120
146
|
{"mkdir", method_mkdir, METH_VARARGS, "Create directory natively."},
|
|
121
147
|
{"rename", method_rename, METH_VARARGS, "Rename file or directory natively."},
|
|
148
|
+
{"rmdir", method_rmdir, METH_VARARGS, "Remove directory natively."},
|
|
149
|
+
{"rm", method_rm, METH_VARARGS, "Remove file or directory natively."},
|
|
122
150
|
{NULL, NULL, 0, NULL},
|
|
123
151
|
};
|
|
124
152
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// c_src/diskops/posix/rm.c
|
|
2
|
+
|
|
3
|
+
#include "../shared/native_errors.h"
|
|
4
|
+
#include <errno.h>
|
|
5
|
+
#include <stdbool.h>
|
|
6
|
+
#include <sys/stat.h>
|
|
7
|
+
#include <unistd.h>
|
|
8
|
+
|
|
9
|
+
Result remove_dir(const char *path, bool force);
|
|
10
|
+
|
|
11
|
+
Result remove_item(const char *path, bool recursive) {
|
|
12
|
+
if (!path || path[0] == '\0') {
|
|
13
|
+
return ERR_INVALID_PATH;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
struct stat st;
|
|
17
|
+
if (lstat(path, &st) != 0) {
|
|
18
|
+
return map_posix_errno(errno);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (S_ISDIR(st.st_mode)) {
|
|
22
|
+
if (!recursive) {
|
|
23
|
+
return ERR_IS_DIR;
|
|
24
|
+
}
|
|
25
|
+
return remove_dir(path, true);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (unlink(path) != 0) {
|
|
29
|
+
return map_posix_errno(errno);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return SUCCESS;
|
|
33
|
+
}
|
|
@@ -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,52 @@
|
|
|
1
|
+
// c_src/diskops/win32/rm.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 remove_dir(const char *path, bool force);
|
|
10
|
+
|
|
11
|
+
Result remove_item(const char *path, bool recursive) {
|
|
12
|
+
if (!path || path[0] == '\0') {
|
|
13
|
+
return ERR_INVALID_PATH;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
wchar_t *wpath = utf8_to_wide(path);
|
|
17
|
+
if (!wpath) {
|
|
18
|
+
return ERR_INVALID_PATH;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
DWORD attrs = GetFileAttributesW(wpath);
|
|
22
|
+
if (attrs == INVALID_FILE_ATTRIBUTES) {
|
|
23
|
+
DWORD err = GetLastError();
|
|
24
|
+
free(wpath);
|
|
25
|
+
return map_win32_error(err);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
bool is_dir = (attrs & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
|
29
|
+
bool is_reparse = (attrs & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
|
|
30
|
+
|
|
31
|
+
if (is_dir && !is_reparse) {
|
|
32
|
+
free(wpath);
|
|
33
|
+
if (!recursive) {
|
|
34
|
+
return ERR_IS_DIR;
|
|
35
|
+
}
|
|
36
|
+
return remove_dir(path, true);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if ((attrs & FILE_ATTRIBUTE_READONLY) != 0) {
|
|
40
|
+
SetFileAttributesW(wpath, attrs & ~FILE_ATTRIBUTE_READONLY);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
BOOL ok = is_dir ? RemoveDirectoryW(wpath) : DeleteFileW(wpath);
|
|
44
|
+
DWORD err = GetLastError();
|
|
45
|
+
free(wpath);
|
|
46
|
+
|
|
47
|
+
if (ok == 0) {
|
|
48
|
+
return map_win32_error(err);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return SUCCESS;
|
|
52
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -13,12 +13,16 @@ if sys.platform == "win32":
|
|
|
13
13
|
sources.append("c_src/diskops/win32/dir.c")
|
|
14
14
|
sources.append("c_src/diskops/win32/mkdir.c")
|
|
15
15
|
sources.append("c_src/diskops/win32/rename.c")
|
|
16
|
+
sources.append("c_src/diskops/win32/rm.c")
|
|
17
|
+
sources.append("c_src/diskops/win32/rmdir.c")
|
|
16
18
|
sources.append("c_src/diskops/win32/touch.c")
|
|
17
19
|
else:
|
|
18
20
|
sources.append("c_src/diskops/posix/cat.c")
|
|
19
21
|
sources.append("c_src/diskops/posix/dir.c")
|
|
20
22
|
sources.append("c_src/diskops/posix/mkdir.c")
|
|
21
23
|
sources.append("c_src/diskops/posix/rename.c")
|
|
24
|
+
sources.append("c_src/diskops/posix/rm.c")
|
|
25
|
+
sources.append("c_src/diskops/posix/rmdir.c")
|
|
22
26
|
sources.append("c_src/diskops/posix/touch.c")
|
|
23
27
|
|
|
24
28
|
native_diskops = Extension(
|
|
@@ -9,6 +9,65 @@ from pathlib import Path
|
|
|
9
9
|
import os
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
def _validate_delete_target(
|
|
13
|
+
target_path: Path, raw_target: str
|
|
14
|
+
) -> tuple[int, str] | None:
|
|
15
|
+
if target_path == target_path.parent or str(target_path) == target_path.anchor:
|
|
16
|
+
return (
|
|
17
|
+
1,
|
|
18
|
+
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
19
|
+
"You cannot delete the root filesystem directory.\n",
|
|
20
|
+
)
|
|
21
|
+
critical_system_dirs = [
|
|
22
|
+
Path.home().parent.resolve(),
|
|
23
|
+
Path.home().resolve(),
|
|
24
|
+
]
|
|
25
|
+
if c.HOST_OS == "Windows":
|
|
26
|
+
system_drive = os.environ.get("SystemDrive", "C:")
|
|
27
|
+
critical_system_dirs.extend(
|
|
28
|
+
[
|
|
29
|
+
Path(f"{system_drive}\\Windows").resolve(),
|
|
30
|
+
Path(f"{system_drive}\\Program Files").resolve(),
|
|
31
|
+
Path(f"{system_drive}\\Program Files (x86)").resolve(),
|
|
32
|
+
]
|
|
33
|
+
)
|
|
34
|
+
else:
|
|
35
|
+
critical_system_dirs.extend(
|
|
36
|
+
[
|
|
37
|
+
Path("/bin").resolve(),
|
|
38
|
+
Path("/etc").resolve(),
|
|
39
|
+
Path("/usr").resolve(),
|
|
40
|
+
Path("/var").resolve(),
|
|
41
|
+
]
|
|
42
|
+
)
|
|
43
|
+
if target_path in critical_system_dirs:
|
|
44
|
+
return (
|
|
45
|
+
1,
|
|
46
|
+
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
47
|
+
f"Target '{raw_target}' is a protected operating system directory.\n",
|
|
48
|
+
)
|
|
49
|
+
if target_path == Path(os.getcwd()).resolve():
|
|
50
|
+
return (
|
|
51
|
+
1,
|
|
52
|
+
"\nSystem Error: Cannot remove current working directory.\n"
|
|
53
|
+
"Switch to a different directory using 'cd' first.\n",
|
|
54
|
+
)
|
|
55
|
+
flyshell_dirs = [
|
|
56
|
+
c.APP_DIR.resolve(),
|
|
57
|
+
c.PACKAGE_ROOT.resolve(),
|
|
58
|
+
c.PROJECT_ROOT.resolve(),
|
|
59
|
+
]
|
|
60
|
+
for protected in flyshell_dirs:
|
|
61
|
+
if target_path == protected or target_path.is_relative_to(protected):
|
|
62
|
+
return (
|
|
63
|
+
1,
|
|
64
|
+
"\nSecurity Error: Flyshell has blocked this action.\n"
|
|
65
|
+
f"Target '{raw_target}' contains or belongs to Flyshell system files.\n"
|
|
66
|
+
"If you wish to delete Flyshell, use the host.\n",
|
|
67
|
+
)
|
|
68
|
+
return None
|
|
69
|
+
|
|
70
|
+
|
|
12
71
|
class Cat(BaseCmd):
|
|
13
72
|
name = "cat"
|
|
14
73
|
description = "Display the contents of a text file"
|
|
@@ -161,6 +220,91 @@ class Rename(BaseCmd):
|
|
|
161
220
|
return (0, f"\nSUCCESS! Renamed '{src_path.name}' -> '{new_path.name}'\n")
|
|
162
221
|
|
|
163
222
|
|
|
223
|
+
class Rm(BaseCmd):
|
|
224
|
+
name = "rm"
|
|
225
|
+
description = "Remove files from the filesystem"
|
|
226
|
+
min_args = 1
|
|
227
|
+
options = "Target file"
|
|
228
|
+
aliases = ["del"]
|
|
229
|
+
|
|
230
|
+
def execute(self, args):
|
|
231
|
+
force = ("-f" in args) or ("--force" in args)
|
|
232
|
+
recursive = ("-r" in args) or ("--recursive" in args)
|
|
233
|
+
flags = {"-f", "--force", "-r", "--recursive"}
|
|
234
|
+
path_tokens = [arg for arg in args if arg not in flags]
|
|
235
|
+
if not path_tokens:
|
|
236
|
+
return (1, "\nCommand Error: No target file or directory specified.\n")
|
|
237
|
+
raw_target = " ".join(path_tokens).strip("\"'")
|
|
238
|
+
target_path = Path(raw_target).expanduser().resolve()
|
|
239
|
+
if not target_path.exists():
|
|
240
|
+
return (1, f"\nSystem Error: Target '{raw_target}' not found.\n")
|
|
241
|
+
blocked = _validate_delete_target(target_path, raw_target)
|
|
242
|
+
if blocked is not None:
|
|
243
|
+
return blocked
|
|
244
|
+
is_directory = target_path.is_dir()
|
|
245
|
+
if is_directory and not recursive:
|
|
246
|
+
return (
|
|
247
|
+
1,
|
|
248
|
+
f"\nCommand Error: '{raw_target}' is a directory.\n"
|
|
249
|
+
"Use '-r' or '--recursive' to remove directories.\n",
|
|
250
|
+
)
|
|
251
|
+
if not force:
|
|
252
|
+
target_type = "directory and all its contents" if is_directory else "file"
|
|
253
|
+
prompt_msg = f"\nAre you sure you want to permanently delete {target_type} '{raw_target}'? [y/n]: "
|
|
254
|
+
try:
|
|
255
|
+
confirm = input(prompt_msg).strip().lower()
|
|
256
|
+
except (KeyboardInterrupt, EOFError):
|
|
257
|
+
return (1, "\nDeletion cancelled by user.\n")
|
|
258
|
+
if confirm != "y":
|
|
259
|
+
return (0, "\nOperation cancelled. No files were deleted.\n")
|
|
260
|
+
if bridge.has_native_support() and hasattr(bridge._native, "rm"):
|
|
261
|
+
code, _ = bridge._native.rm(str(target_path), recursive)
|
|
262
|
+
else:
|
|
263
|
+
code, _ = legacy.lgc_rm(target_path, recursive)
|
|
264
|
+
if code != 0:
|
|
265
|
+
return bridge.translate_error(code, raw_target)
|
|
266
|
+
if is_directory:
|
|
267
|
+
return (
|
|
268
|
+
0,
|
|
269
|
+
f"\nSUCCESS! Deleted directory '{raw_target}' and all its contents.\n",
|
|
270
|
+
)
|
|
271
|
+
return (0, f"\nSUCCESS! Deleted file '{raw_target}'\n")
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
class RmDir(BaseCmd):
|
|
275
|
+
name = "rmdir"
|
|
276
|
+
description = "Remove the specified directory"
|
|
277
|
+
min_args = 1
|
|
278
|
+
options = "Target directory"
|
|
279
|
+
aliases = []
|
|
280
|
+
|
|
281
|
+
def execute(self, args):
|
|
282
|
+
force = ("-f" in args) or ("--force" in args)
|
|
283
|
+
path_tokens = [arg for arg in args if arg not in ("-f", "--force")]
|
|
284
|
+
if not path_tokens:
|
|
285
|
+
return (1, "\nCommand Error: Target directory not specified.\n")
|
|
286
|
+
raw_target = " ".join(path_tokens).strip("\"'")
|
|
287
|
+
target_path = Path(raw_target).expanduser().resolve()
|
|
288
|
+
if not target_path.exists():
|
|
289
|
+
return (1, f"\nSystem Error: Target '{raw_target}' not found.\n")
|
|
290
|
+
blocked = _validate_delete_target(target_path, raw_target)
|
|
291
|
+
if blocked is not None:
|
|
292
|
+
return blocked
|
|
293
|
+
if bridge.has_native_support() and hasattr(bridge._native, "rmdir"):
|
|
294
|
+
code, _ = bridge._native.rmdir(str(target_path), force)
|
|
295
|
+
else:
|
|
296
|
+
code, _ = legacy.lgc_rmdir(target_path, force)
|
|
297
|
+
if code != 0:
|
|
298
|
+
if code == -6 and not force:
|
|
299
|
+
return (
|
|
300
|
+
1,
|
|
301
|
+
f"\nDirectory Error: Directory '{raw_target}' is not empty.\n"
|
|
302
|
+
"Use '-f' or '--force' to remove a non-empty directory and its contents.\n",
|
|
303
|
+
)
|
|
304
|
+
return bridge.translate_error(code, raw_target)
|
|
305
|
+
return (0, f"\nSUCCESS! Removed directory '{raw_target}'\n")
|
|
306
|
+
|
|
307
|
+
|
|
164
308
|
class Touch(BaseCmd):
|
|
165
309
|
name = "touch"
|
|
166
310
|
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]:
|
|
@@ -93,6 +94,50 @@ def lgc_rename(src_path: Path, dst_path: Path) -> tuple[int, str]:
|
|
|
93
94
|
return (-99, "") # ERR_UNKNOWN
|
|
94
95
|
|
|
95
96
|
|
|
97
|
+
def lgc_rm(target_path: Path, recursive: bool = False) -> tuple[int, str]:
|
|
98
|
+
if not target_path.exists() and not target_path.is_symlink():
|
|
99
|
+
return (-1, "") # ERR_NOT_FOUND
|
|
100
|
+
is_dir = target_path.is_dir() and not target_path.is_symlink()
|
|
101
|
+
if is_dir and not recursive:
|
|
102
|
+
return (-3, "") # ERR_IS_DIR
|
|
103
|
+
try:
|
|
104
|
+
if is_dir:
|
|
105
|
+
shutil.rmtree(target_path)
|
|
106
|
+
else:
|
|
107
|
+
os.remove(target_path)
|
|
108
|
+
return (0, "") # SUCCESS
|
|
109
|
+
except PermissionError:
|
|
110
|
+
return (-2, "") # ERR_PERMISSION
|
|
111
|
+
except OSError:
|
|
112
|
+
return (-13, "") # ERR_IO
|
|
113
|
+
except Exception:
|
|
114
|
+
return (-99, "") # ERR_UNKNOWN
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def lgc_rmdir(target_path: Path, force: bool = False) -> tuple[int, str]:
|
|
118
|
+
if not target_path.exists():
|
|
119
|
+
return (-1, "") # ERR_NOT_FOUND
|
|
120
|
+
if not target_path.is_dir():
|
|
121
|
+
return (-4, "") # ERR_NOT_DIR
|
|
122
|
+
try:
|
|
123
|
+
has_contents = any(target_path.iterdir())
|
|
124
|
+
if has_contents and not force:
|
|
125
|
+
return (-6, "") # ERR_NOT_EMPTY
|
|
126
|
+
if has_contents and force:
|
|
127
|
+
shutil.rmtree(target_path)
|
|
128
|
+
else:
|
|
129
|
+
os.rmdir(target_path)
|
|
130
|
+
return (0, "") # SUCCESS
|
|
131
|
+
except PermissionError:
|
|
132
|
+
return (-2, "") # ERR_PERMISSION
|
|
133
|
+
except OSError as e:
|
|
134
|
+
if getattr(e, "errno", None) in (39, 66, 145):
|
|
135
|
+
return (-6, "") # ERR_NOT_EMPTY
|
|
136
|
+
return (-13, "") # ERR_IO
|
|
137
|
+
except Exception:
|
|
138
|
+
return (-99, "") # ERR_UNKNOWN
|
|
139
|
+
|
|
140
|
+
|
|
96
141
|
def lgc_touch(target_path: Path) -> tuple[int, str]:
|
|
97
142
|
if target_path.is_dir():
|
|
98
143
|
return (-3, "") # ERR_IS_DIR
|
|
@@ -8,6 +8,8 @@ c_src/diskops/posix/cat.c
|
|
|
8
8
|
c_src/diskops/posix/dir.c
|
|
9
9
|
c_src/diskops/posix/mkdir.c
|
|
10
10
|
c_src/diskops/posix/rename.c
|
|
11
|
+
c_src/diskops/posix/rm.c
|
|
12
|
+
c_src/diskops/posix/rmdir.c
|
|
11
13
|
c_src/diskops/posix/touch.c
|
|
12
14
|
c_src/diskops/shared/dir_types.c
|
|
13
15
|
c_src/diskops/shared/dir_types.h
|
|
@@ -17,6 +19,8 @@ c_src/diskops/win32/cat.c
|
|
|
17
19
|
c_src/diskops/win32/dir.c
|
|
18
20
|
c_src/diskops/win32/mkdir.c
|
|
19
21
|
c_src/diskops/win32/rename.c
|
|
22
|
+
c_src/diskops/win32/rm.c
|
|
23
|
+
c_src/diskops/win32/rmdir.c
|
|
20
24
|
c_src/diskops/win32/touch.c
|
|
21
25
|
src/flyshell/__init__.py
|
|
22
26
|
src/flyshell/constants.py
|
|
@@ -11,6 +11,70 @@ def test_native_extension_loaded():
|
|
|
11
11
|
assert bridge._native.ping() == 42
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
def test_native_rm_file_and_recursive_dir(tmp_path):
|
|
15
|
+
cmd = handler.Rm()
|
|
16
|
+
target_file = tmp_path / "delete_me.txt"
|
|
17
|
+
target_file.write_text("bye", encoding="utf-8")
|
|
18
|
+
exit_code, msg = cmd.execute(["-f", str(target_file)])
|
|
19
|
+
assert exit_code == 0
|
|
20
|
+
assert "Deleted file" in msg
|
|
21
|
+
assert not target_file.exists()
|
|
22
|
+
target_dir = tmp_path / "sub_tree"
|
|
23
|
+
(target_dir / "nested").mkdir(parents=True)
|
|
24
|
+
(target_dir / "nested" / "file.txt").write_text("x", encoding="utf-8")
|
|
25
|
+
exit_code, msg = cmd.execute(["-f", str(target_dir)])
|
|
26
|
+
assert exit_code == 1
|
|
27
|
+
assert "is a directory" in msg
|
|
28
|
+
assert target_dir.exists()
|
|
29
|
+
exit_code, msg = cmd.execute(["-f", "-r", str(target_dir)])
|
|
30
|
+
assert exit_code == 0
|
|
31
|
+
assert "Deleted directory" in msg
|
|
32
|
+
assert not target_dir.exists()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_native_rm_errors(tmp_path):
|
|
36
|
+
cmd = handler.Rm()
|
|
37
|
+
exit_code, msg = cmd.execute(["-f", str(tmp_path / "missing.txt")])
|
|
38
|
+
assert exit_code == 1
|
|
39
|
+
assert "not found" in msg
|
|
40
|
+
sub_dir = tmp_path / "dir_only"
|
|
41
|
+
sub_dir.mkdir()
|
|
42
|
+
code, _ = bridge._native.rm(str(sub_dir), False)
|
|
43
|
+
assert code == -3 # ERR_IS_DIR
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def test_native_rmdir_empty_and_force(tmp_path):
|
|
47
|
+
cmd = handler.RmDir()
|
|
48
|
+
empty_dir = tmp_path / "empty_folder"
|
|
49
|
+
empty_dir.mkdir()
|
|
50
|
+
exit_code, msg = cmd.execute([str(empty_dir)])
|
|
51
|
+
assert exit_code == 0
|
|
52
|
+
assert "Removed directory" in msg
|
|
53
|
+
assert not empty_dir.exists()
|
|
54
|
+
non_empty = tmp_path / "full_folder"
|
|
55
|
+
nested = non_empty / "sub_folder"
|
|
56
|
+
nested.mkdir(parents=True)
|
|
57
|
+
(nested / "item.txt").write_text("data", encoding="utf-8")
|
|
58
|
+
exit_code, msg = cmd.execute([str(non_empty)])
|
|
59
|
+
assert exit_code == 1
|
|
60
|
+
assert "not empty" in msg
|
|
61
|
+
assert non_empty.exists()
|
|
62
|
+
exit_code, msg = cmd.execute(["-f", str(non_empty)])
|
|
63
|
+
assert exit_code == 0
|
|
64
|
+
assert not non_empty.exists()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_native_rmdir_errors(tmp_path):
|
|
68
|
+
regular_file = tmp_path / "not_a_dir.txt"
|
|
69
|
+
regular_file.write_text("hello", encoding="utf-8")
|
|
70
|
+
code, _ = bridge._native.rmdir(str(regular_file), False)
|
|
71
|
+
assert code == -4 # ERR_NOT_DIR
|
|
72
|
+
cmd = handler.RmDir()
|
|
73
|
+
exit_code, msg = cmd.execute([str(tmp_path / "missing_folder")])
|
|
74
|
+
assert exit_code == 1
|
|
75
|
+
assert "not found" in msg
|
|
76
|
+
|
|
77
|
+
|
|
14
78
|
def test_native_cat_reads_and_formats_content(tmp_path):
|
|
15
79
|
file_path = tmp_path / "native_cat.txt"
|
|
16
80
|
file_path.write_text("alpha\nbeta\ngamma\ndelta\n", encoding="utf-8")
|
|
@@ -12,6 +12,40 @@ def force_legacy_backend(monkeypatch):
|
|
|
12
12
|
monkeypatch.setattr(bridge, "has_native_support", lambda: False)
|
|
13
13
|
|
|
14
14
|
|
|
15
|
+
def test_legacy_rm_file_and_recursive_dir(tmp_path):
|
|
16
|
+
cmd = handler.Rm()
|
|
17
|
+
target_file = tmp_path / "lgc_del.txt"
|
|
18
|
+
target_file.write_text("bye", encoding="utf-8")
|
|
19
|
+
exit_code, msg = cmd.execute(["-f", str(target_file)])
|
|
20
|
+
assert exit_code == 0
|
|
21
|
+
assert not target_file.exists()
|
|
22
|
+
target_dir = tmp_path / "lgc_dir"
|
|
23
|
+
target_dir.mkdir()
|
|
24
|
+
(target_dir / "a.txt").write_text("1", encoding="utf-8")
|
|
25
|
+
code, _ = legacy.lgc_rm(target_dir, recursive=False)
|
|
26
|
+
assert code == -3 # ERR_IS_DIR
|
|
27
|
+
exit_code, msg = cmd.execute(["-f", "-r", str(target_dir)])
|
|
28
|
+
assert exit_code == 0
|
|
29
|
+
assert not target_dir.exists()
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_legacy_rmdir_empty_and_force(tmp_path):
|
|
33
|
+
cmd = handler.RmDir()
|
|
34
|
+
non_empty = tmp_path / "legacy_full"
|
|
35
|
+
(non_empty / "child").mkdir(parents=True)
|
|
36
|
+
(non_empty / "child" / "file.txt").write_text("abc", encoding="utf-8")
|
|
37
|
+
exit_code, msg = cmd.execute([str(non_empty)])
|
|
38
|
+
assert exit_code == 1
|
|
39
|
+
assert "not empty" in msg
|
|
40
|
+
exit_code, msg = cmd.execute(["-f", str(non_empty)])
|
|
41
|
+
assert exit_code == 0
|
|
42
|
+
assert not non_empty.exists()
|
|
43
|
+
regular_file = tmp_path / "file.txt"
|
|
44
|
+
regular_file.write_text("x", encoding="utf-8")
|
|
45
|
+
code, _ = legacy.lgc_rmdir(regular_file, force=False)
|
|
46
|
+
assert code == -4 # ERR_NOT_DIR
|
|
47
|
+
|
|
48
|
+
|
|
15
49
|
def test_legacy_rename_file_and_errors(tmp_path):
|
|
16
50
|
src = tmp_path / "legacy_old.txt"
|
|
17
51
|
src.write_text("hello", encoding="utf-8")
|
|
@@ -35,16 +35,3 @@ def test_rm_file_and_directory_recursive(tmp_path):
|
|
|
35
35
|
code, msg = cmd.execute(["-f", "-r", str(target_dir)])
|
|
36
36
|
assert code == 0
|
|
37
37
|
assert not target_dir.exists()
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def test_rmdir_empty_and_non_empty(tmp_path):
|
|
41
|
-
target_dir = tmp_path / "removable"
|
|
42
|
-
target_dir.mkdir()
|
|
43
|
-
cmd = diskops.RmDir()
|
|
44
|
-
(target_dir / "file.txt").write_text("data")
|
|
45
|
-
code, msg = cmd.execute([str(target_dir)])
|
|
46
|
-
assert code == 1
|
|
47
|
-
assert "not empty" in msg
|
|
48
|
-
code, msg = cmd.execute(["-f", str(target_dir)])
|
|
49
|
-
assert code == 0
|
|
50
|
-
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
|