flyshell 1.4.5__tar.gz → 1.4.7__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.
Files changed (70) hide show
  1. {flyshell-1.4.5/src/flyshell.egg-info → flyshell-1.4.7}/PKG-INFO +1 -1
  2. {flyshell-1.4.5 → flyshell-1.4.7}/c_src/diskops/diskops.c +28 -0
  3. flyshell-1.4.7/c_src/diskops/posix/mkdir.c +58 -0
  4. flyshell-1.4.7/c_src/diskops/posix/rename.c +31 -0
  5. flyshell-1.4.7/c_src/diskops/win32/mkdir.c +72 -0
  6. flyshell-1.4.7/c_src/diskops/win32/rename.c +47 -0
  7. {flyshell-1.4.5 → flyshell-1.4.7}/setup.py +4 -0
  8. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/builtin/diskops.py +0 -75
  9. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/constants.py +2 -2
  10. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/core/directory.py +2 -2
  11. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/native/diskops_handler.py +71 -0
  12. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/native/legacy/diskops.py +46 -0
  13. {flyshell-1.4.5 → flyshell-1.4.7/src/flyshell.egg-info}/PKG-INFO +1 -1
  14. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell.egg-info/SOURCES.txt +4 -0
  15. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_diskops_ext.py +89 -22
  16. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_diskops_lgc.py +69 -27
  17. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_diskops_old.py +0 -25
  18. {flyshell-1.4.5 → flyshell-1.4.7}/LICENSE +0 -0
  19. {flyshell-1.4.5 → flyshell-1.4.7}/MANIFEST.in +0 -0
  20. {flyshell-1.4.5 → flyshell-1.4.7}/README.md +0 -0
  21. {flyshell-1.4.5 → flyshell-1.4.7}/c_src/diskops/posix/cat.c +0 -0
  22. {flyshell-1.4.5 → flyshell-1.4.7}/c_src/diskops/posix/dir.c +0 -0
  23. {flyshell-1.4.5 → flyshell-1.4.7}/c_src/diskops/posix/touch.c +0 -0
  24. {flyshell-1.4.5 → flyshell-1.4.7}/c_src/diskops/shared/dir_types.c +0 -0
  25. {flyshell-1.4.5 → flyshell-1.4.7}/c_src/diskops/shared/dir_types.h +0 -0
  26. {flyshell-1.4.5 → flyshell-1.4.7}/c_src/diskops/shared/native_errors.h +0 -0
  27. {flyshell-1.4.5 → flyshell-1.4.7}/c_src/diskops/shared/win32_utf.h +0 -0
  28. {flyshell-1.4.5 → flyshell-1.4.7}/c_src/diskops/win32/cat.c +0 -0
  29. {flyshell-1.4.5 → flyshell-1.4.7}/c_src/diskops/win32/dir.c +0 -0
  30. {flyshell-1.4.5 → flyshell-1.4.7}/c_src/diskops/win32/touch.c +0 -0
  31. {flyshell-1.4.5 → flyshell-1.4.7}/pyproject.toml +0 -0
  32. {flyshell-1.4.5 → flyshell-1.4.7}/setup.cfg +0 -0
  33. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/__init__.py +0 -0
  34. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/abstract/__init__.py +0 -0
  35. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/abstract/base_cmd.py +0 -0
  36. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/abstract/base_plugin.py +0 -0
  37. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/abstract/parent_cmd.py +0 -0
  38. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/accounts/__init__.py +0 -0
  39. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/accounts/auth.py +0 -0
  40. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/bin/__init__.py +0 -0
  41. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/builtin/__init__.py +0 -0
  42. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/builtin/fs.py +0 -0
  43. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/builtin/pkg.py +0 -0
  44. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/builtin/system.py +0 -0
  45. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/builtin/utils.py +0 -0
  46. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/core/__init__.py +0 -0
  47. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/core/console.py +0 -0
  48. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/core/data.py +0 -0
  49. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/main.py +0 -0
  50. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/native/__init__.py +0 -0
  51. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/native/diskops_bridge.py +0 -0
  52. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/native/legacy/__init__.py +0 -0
  53. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/startup/__init__.py +0 -0
  54. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/startup/deps.py +0 -0
  55. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/startup/env.py +0 -0
  56. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell/startup/loader.py +0 -0
  57. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell.egg-info/dependency_links.txt +0 -0
  58. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell.egg-info/entry_points.txt +0 -0
  59. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell.egg-info/requires.txt +0 -0
  60. {flyshell-1.4.5 → flyshell-1.4.7}/src/flyshell.egg-info/top_level.txt +0 -0
  61. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_auth.py +0 -0
  62. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_data.py +0 -0
  63. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_deps.py +0 -0
  64. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_directory.py +0 -0
  65. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_env.py +0 -0
  66. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_fs.py +0 -0
  67. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_loader.py +0 -0
  68. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_pkg.py +0 -0
  69. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_security.py +0 -0
  70. {flyshell-1.4.5 → flyshell-1.4.7}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flyshell
3
- Version: 1.4.5
3
+ Version: 1.4.7
4
4
  Summary: A modular, zero-dependency command-line environment in Python.
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
@@ -11,6 +11,10 @@ Result touch(const char *path);
11
11
 
12
12
  Result list_dir(const char *path, DirList *out_list);
13
13
 
14
+ Result make_dir(const char *path, bool parents);
15
+
16
+ Result rename_item(const char *src, const char *dst);
17
+
14
18
  static PyObject *method_ping(PyObject *self, PyObject *args) {
15
19
  return PyLong_FromLong(42);
16
20
  }
@@ -86,11 +90,35 @@ static PyObject *method_dir(PyObject *self, PyObject *args) {
86
90
  return Py_BuildValue("(iN)", (int)SUCCESS, py_list);
87
91
  }
88
92
 
93
+ static PyObject *method_mkdir(PyObject *self, PyObject *args) {
94
+ const char *path;
95
+ int parents = 0;
96
+ if (!PyArg_ParseTuple(args, "s|p", &path, &parents)) {
97
+ return NULL;
98
+ }
99
+
100
+ Result res = make_dir(path, parents != 0);
101
+ return Py_BuildValue("(is)", (int)res, "");
102
+ }
103
+
104
+ static PyObject *method_rename(PyObject *self, PyObject *args) {
105
+ const char *src;
106
+ const char *dst;
107
+ if (!PyArg_ParseTuple(args, "ss", &src, &dst)) {
108
+ return NULL;
109
+ }
110
+
111
+ Result res = rename_item(src, dst);
112
+ return Py_BuildValue("(is)", (int)res, "");
113
+ }
114
+
89
115
  static PyMethodDef DiskopsMethods[] = {
90
116
  {"ping", method_ping, METH_NOARGS, "Health check ping."},
91
117
  {"cat", method_cat, METH_VARARGS, "Read file content natively."},
92
118
  {"touch", method_touch, METH_VARARGS, "Touch or create file natively."},
93
119
  {"dir", method_dir, METH_VARARGS, "List directory contents natively."},
120
+ {"mkdir", method_mkdir, METH_VARARGS, "Create directory natively."},
121
+ {"rename", method_rename, METH_VARARGS, "Rename file or directory natively."},
94
122
  {NULL, NULL, 0, NULL},
95
123
  };
96
124
 
@@ -0,0 +1,58 @@
1
+ // c_src/diskops/posix/mkdir.c
2
+
3
+ #include "../shared/native_errors.h"
4
+ #include <errno.h>
5
+ #include <stdbool.h>
6
+ #include <stdlib.h>
7
+ #include <string.h>
8
+ #include <sys/stat.h>
9
+
10
+ static Result make_single_dir_posix(const char *path, bool ignore_existing) {
11
+ if (mkdir(path, 0777) == 0) {
12
+ return SUCCESS;
13
+ }
14
+ if (errno == EEXIST && ignore_existing) {
15
+ struct stat st;
16
+ if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
17
+ return SUCCESS;
18
+ }
19
+ return ERR_NOT_DIR;
20
+ }
21
+ return map_posix_errno(errno);
22
+ }
23
+
24
+ Result make_dir(const char *path, bool parents) {
25
+ if (!path || path[0] == '\0') {
26
+ return ERR_INVALID_PATH;
27
+ }
28
+
29
+ if (!parents) {
30
+ return make_single_dir_posix(path, false);
31
+ }
32
+
33
+ char *copy = strdup(path);
34
+ if (!copy) {
35
+ return ERR_IO;
36
+ }
37
+
38
+ size_t len = strlen(copy);
39
+ while (len > 1 && copy[len - 1] == '/') {
40
+ copy[--len] = '\0';
41
+ }
42
+
43
+ for (size_t i = 1; i < len; ++i) {
44
+ if (copy[i] == '/') {
45
+ copy[i] = '\0';
46
+ Result res = make_single_dir_posix(copy, true);
47
+ if (res != SUCCESS) {
48
+ free(copy);
49
+ return res;
50
+ }
51
+ copy[i] = '/';
52
+ }
53
+ }
54
+
55
+ Result final_res = make_single_dir_posix(copy, true);
56
+ free(copy);
57
+ return final_res;
58
+ }
@@ -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,72 @@
1
+ // c_src/diskops/win32/mkdir.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
+ static Result make_single_dir_win32(const wchar_t *wpath, bool ignore_existing) {
10
+ if (CreateDirectoryW(wpath, NULL) != 0) {
11
+ return SUCCESS;
12
+ }
13
+ DWORD err = GetLastError();
14
+ if (err == ERROR_ALREADY_EXISTS && ignore_existing) {
15
+ DWORD attrs = GetFileAttributesW(wpath);
16
+ if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY) != 0) {
17
+ return SUCCESS;
18
+ }
19
+ return ERR_NOT_DIR;
20
+ }
21
+ return map_win32_error(err);
22
+ }
23
+
24
+ Result make_dir(const char *path, bool parents) {
25
+ if (!path || path[0] == '\0') {
26
+ return ERR_INVALID_PATH;
27
+ }
28
+
29
+ wchar_t *wpath = utf8_to_wide(path);
30
+ if (!wpath) {
31
+ return ERR_INVALID_PATH;
32
+ }
33
+
34
+ if (!parents) {
35
+ Result res = make_single_dir_win32(wpath, false);
36
+ free(wpath);
37
+ return res;
38
+ }
39
+
40
+ size_t len = wcslen(wpath);
41
+ while (len > 1 && (wpath[len - 1] == L'\\' || wpath[len - 1] == L'/')) {
42
+ if (len == 3 && wpath[1] == L':') {
43
+ break;
44
+ }
45
+ wpath[--len] = L'\0';
46
+ }
47
+
48
+ size_t start = 1;
49
+ if (len >= 3 && wpath[1] == L':' && (wpath[2] == L'\\' || wpath[2] == L'/')) {
50
+ start = 3;
51
+ } else if (len >= 2 && (wpath[0] == L'\\' || wpath[0] == L'/') &&
52
+ (wpath[1] == L'\\' || wpath[1] == L'/')) {
53
+ start = 2;
54
+ }
55
+
56
+ for (size_t i = start; i < len; ++i) {
57
+ if (wpath[i] == L'\\' || wpath[i] == L'/') {
58
+ wchar_t orig = wpath[i];
59
+ wpath[i] = L'\0';
60
+ Result res = make_single_dir_win32(wpath, true);
61
+ if (res != SUCCESS) {
62
+ free(wpath);
63
+ return res;
64
+ }
65
+ wpath[i] = orig;
66
+ }
67
+ }
68
+
69
+ Result final_res = make_single_dir_win32(wpath, true);
70
+ free(wpath);
71
+ return final_res;
72
+ }
@@ -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
+ }
@@ -11,10 +11,14 @@ sources = [
11
11
  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
+ sources.append("c_src/diskops/win32/mkdir.c")
15
+ sources.append("c_src/diskops/win32/rename.c")
14
16
  sources.append("c_src/diskops/win32/touch.c")
15
17
  else:
16
18
  sources.append("c_src/diskops/posix/cat.c")
17
19
  sources.append("c_src/diskops/posix/dir.c")
20
+ sources.append("c_src/diskops/posix/mkdir.c")
21
+ sources.append("c_src/diskops/posix/rename.c")
18
22
  sources.append("c_src/diskops/posix/touch.c")
19
23
 
20
24
  native_diskops = Extension(
@@ -71,36 +71,6 @@ class Copy(BaseCmd):
71
71
  return (1, f"\nSystem Error: Failed to copy '{raw_src}' ({e})\n")
72
72
 
73
73
 
74
- class MkDir(BaseCmd):
75
- name = "mkdir"
76
- description = "Create a new directory from the current working directory"
77
- min_args = 1
78
- options = "Directory name"
79
- aliases = ["md"]
80
-
81
- def execute(self, args):
82
- use_parents = ("-p" in args) or ("--parents" in args)
83
- path_tokens = [arg for arg in args if arg not in ("-p", "--parents")]
84
- target = " ".join(path_tokens).strip("\"'")
85
- try:
86
- if use_parents:
87
- os.makedirs(target, exist_ok=True)
88
- else:
89
- os.mkdir(target)
90
- return (0, f"\nSUCCESS! Created directory '{target}'\n")
91
- except FileExistsError:
92
- return (1, f"\nSystem Error: Directory '{target}' already exists.\n")
93
- except FileNotFoundError:
94
- return (
95
- 1,
96
- "\nSystem Error: Parent directory does not exist. Use '-p' or '--parents' to create parent directories.\n",
97
- )
98
- except PermissionError:
99
- return (1, f"\nSystem Error: Permission denied. Cannot create '{target}'\n")
100
- except Exception as e:
101
- return (1, f"\nSystem Error: Unable to create directory '{target}' ({e})\n")
102
-
103
-
104
74
  class Move(BaseCmd):
105
75
  name = "mv"
106
76
  description = "Move or relocate files and directories"
@@ -171,51 +141,6 @@ class Move(BaseCmd):
171
141
  return (1, f"\nSystem Error: Failed to move '{raw_src}' ({e})\n")
172
142
 
173
143
 
174
- class Rename(BaseCmd):
175
- name = "rename"
176
- description = "Rename a file or directory"
177
- min_args = 2
178
- options = "Old name, then new name"
179
- aliases = []
180
-
181
- def execute(self, args):
182
- raw_src = args[0].strip("\"'")
183
- raw_new_name = args[1].strip("\"'")
184
- if raw_new_name in (".", "..") or "/" in raw_new_name or "\\" in raw_new_name:
185
- return (1, "\nCommand Error: Invalid file name.\n")
186
- src_path = Path(raw_src).expanduser().resolve()
187
- if not src_path.exists():
188
- return (1, f"\nSystem Error: Target '{raw_src}' not found.\n")
189
- flyshell_dirs = [
190
- c.APP_DIR.resolve(),
191
- c.PACKAGE_ROOT.resolve(),
192
- c.PROJECT_ROOT.resolve(),
193
- ]
194
- for protected in flyshell_dirs:
195
- if src_path == protected or src_path.is_relative_to(protected):
196
- return (
197
- 1,
198
- "\nSecurity Error: Flyshell has blocked this action.\n"
199
- f"Target '{raw_src}' contains or belongs to Flyshell system files.\n",
200
- )
201
- new_path = src_path.parent / raw_new_name
202
- if new_path.exists():
203
- return (
204
- 1,
205
- f"\nSystem Error: An item named '{raw_new_name}' already exists in this folder.\n",
206
- )
207
- try:
208
- src_path.rename(new_path)
209
- return (0, f"\nSUCCESS! Renamed '{src_path.name}' -> '{new_path.name}'\n")
210
- except PermissionError:
211
- return (
212
- 1,
213
- f"\nSystem Error: Permission denied. Cannot rename '{raw_src}'\n",
214
- )
215
- except Exception as e:
216
- return (1, f"\nSystem Error: Failed to rename '{raw_src}' ({e})\n")
217
-
218
-
219
144
  class Rm(BaseCmd):
220
145
  name = "rm"
221
146
  description = "Remove files from the filesystem"
@@ -5,8 +5,8 @@ import os
5
5
  import platform
6
6
  import time
7
7
 
8
- BUILD = 159
9
- VERSION = "1.4.5"
8
+ BUILD = 161
9
+ VERSION = "1.4.7"
10
10
 
11
11
 
12
12
  def _resolve_app_dir() -> Path:
@@ -65,12 +65,12 @@ INSTALLED_COMMANDS: list[BaseCmd] = [
65
65
  utils.History(),
66
66
  utils.Kill(),
67
67
  auth.Lock(),
68
- diskops_legacy.MkDir(),
68
+ diskops.MkDir(),
69
69
  diskops_legacy.Move(),
70
70
  system.OpenFile(),
71
71
  pkg.Pkg(),
72
72
  utils.Reboot(),
73
- diskops_legacy.Rename(),
73
+ diskops.Rename(),
74
74
  diskops_legacy.Rm(),
75
75
  diskops_legacy.RmDir(),
76
76
  utils.Sleep(),
@@ -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
@@ -90,6 +91,76 @@ class Dir(BaseCmd):
90
91
  return (0, "\n".join(lines))
91
92
 
92
93
 
94
+ class MkDir(BaseCmd):
95
+ name = "mkdir"
96
+ description = "Create a new directory from the current working directory"
97
+ min_args = 1
98
+ options = "Directory name"
99
+ aliases = ["md"]
100
+
101
+ def execute(self, args):
102
+ use_parents = ("-p" in args) or ("--parents" in args)
103
+ path_tokens = [arg for arg in args if arg not in ("-p", "--parents")]
104
+ if not path_tokens:
105
+ return (1, "\nCommand Error: Directory name not specified.\n")
106
+ raw_target = " ".join(path_tokens).strip("\"'")
107
+ target_path = Path(raw_target).expanduser()
108
+ if bridge.has_native_support() and hasattr(bridge._native, "mkdir"):
109
+ code, _ = bridge._native.mkdir(str(target_path), use_parents)
110
+ else:
111
+ code, _ = legacy.lgc_mkdir(target_path, use_parents)
112
+ if code != 0:
113
+ if code == -1 and not use_parents:
114
+ return (
115
+ 1,
116
+ "\nSystem Error: Parent directory does not exist. Use '-p' or '--parents' to create parent directories.\n",
117
+ )
118
+ return bridge.translate_error(code, raw_target)
119
+ return (0, f"\nSUCCESS! Created directory '{raw_target}'\n")
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
+
93
164
  class Touch(BaseCmd):
94
165
  name = "touch"
95
166
  description = "Create an empty file or update existing file timestamps"
@@ -47,6 +47,52 @@ def lgc_dir(target_path: Path) -> tuple[int, list[tuple[str, bool]]]:
47
47
  return (-99, []) # ERR_UNKNOWN
48
48
 
49
49
 
50
+ def lgc_mkdir(target_path: Path, parents: bool = False) -> tuple[int, str]:
51
+ try:
52
+ if parents:
53
+ os.makedirs(target_path, exist_ok=True)
54
+ else:
55
+ os.mkdir(target_path)
56
+ return (0, "") # SUCCESS
57
+ except FileExistsError:
58
+ return (-5, "") # ERR_EXISTS
59
+ except NotADirectoryError:
60
+ return (-4, "") # ERR_NOT_DIR
61
+ except FileNotFoundError:
62
+ for parent in target_path.parents:
63
+ if parent.exists() and not parent.is_dir():
64
+ return (-4, "") # ERR_NOT_DIR
65
+ return (-1, "") # ERR_NOT_FOUND
66
+ except PermissionError:
67
+ return (-2, "") # ERR_PERMISSION
68
+ except OSError as e:
69
+ if getattr(e, "errno", None) == 28:
70
+ return (-12, "") # ERR_NO_SPACE
71
+ return (-13, "") # ERR_IO
72
+ except Exception:
73
+ return (-99, "") # ERR_UNKNOWN
74
+
75
+
76
+ def lgc_rename(src_path: Path, dst_path: Path) -> tuple[int, str]:
77
+ if not src_path.exists():
78
+ return (-1, "") # ERR_NOT_FOUND
79
+ if src_path == dst_path:
80
+ return (-7, "") # ERR_SAME_FILE
81
+ if dst_path.exists():
82
+ return (-5, "") # ERR_EXISTS
83
+ try:
84
+ src_path.rename(dst_path)
85
+ return (0, "") # SUCCESS
86
+ except PermissionError:
87
+ return (-2, "") # ERR_PERMISSION
88
+ except OSError as e:
89
+ if getattr(e, "errno", None) == 18:
90
+ return (-10, "") # ERR_XDEV
91
+ return (-13, "") # ERR_IO
92
+ except Exception:
93
+ return (-99, "") # ERR_UNKNOWN
94
+
95
+
50
96
  def lgc_touch(target_path: Path) -> tuple[int, str]:
51
97
  if target_path.is_dir():
52
98
  return (-3, "") # ERR_IS_DIR
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flyshell
3
- Version: 1.4.5
3
+ Version: 1.4.7
4
4
  Summary: A modular, zero-dependency command-line environment in Python.
5
5
  License-Expression: MIT
6
6
  Requires-Python: >=3.10
@@ -6,6 +6,8 @@ setup.py
6
6
  c_src/diskops/diskops.c
7
7
  c_src/diskops/posix/cat.c
8
8
  c_src/diskops/posix/dir.c
9
+ c_src/diskops/posix/mkdir.c
10
+ c_src/diskops/posix/rename.c
9
11
  c_src/diskops/posix/touch.c
10
12
  c_src/diskops/shared/dir_types.c
11
13
  c_src/diskops/shared/dir_types.h
@@ -13,6 +15,8 @@ c_src/diskops/shared/native_errors.h
13
15
  c_src/diskops/shared/win32_utf.h
14
16
  c_src/diskops/win32/cat.c
15
17
  c_src/diskops/win32/dir.c
18
+ c_src/diskops/win32/mkdir.c
19
+ c_src/diskops/win32/rename.c
16
20
  c_src/diskops/win32/touch.c
17
21
  src/flyshell/__init__.py
18
22
  src/flyshell/constants.py
@@ -11,27 +11,6 @@ def test_native_extension_loaded():
11
11
  assert bridge._native.ping() == 42
12
12
 
13
13
 
14
- def test_native_touch_creates_and_updates_file(tmp_path):
15
- target = tmp_path / "native_touch.txt"
16
- code, _ = bridge._native.touch(str(target))
17
- assert code == 0
18
- assert target.exists()
19
- cmd = handler.Touch()
20
- exit_code, msg = cmd.execute([str(target)])
21
- assert exit_code == 0
22
- assert "touched successfully" in msg
23
-
24
-
25
- def test_native_touch_errors(tmp_path):
26
- missing_parent = tmp_path / "no_such_dir" / "file.txt"
27
- code, _ = bridge._native.touch(str(missing_parent))
28
- assert code == -1
29
- cmd = handler.Touch()
30
- exit_code, msg = cmd.execute([str(tmp_path)])
31
- assert exit_code == 1
32
- assert "Target is a directory, not a file" in msg
33
-
34
-
35
14
  def test_native_cat_reads_and_formats_content(tmp_path):
36
15
  file_path = tmp_path / "native_cat.txt"
37
16
  file_path.write_text("alpha\nbeta\ngamma\ndelta\n", encoding="utf-8")
@@ -82,9 +61,97 @@ def test_native_dir_lists_entries_and_handles_errors(tmp_path):
82
61
  assert "Target is not a directory" in msg
83
62
 
84
63
 
64
+ def test_native_mkdir_creates_and_handles_parents(tmp_path):
65
+ cmd = handler.MkDir()
66
+ target = tmp_path / "native_folder"
67
+ code, _ = bridge._native.mkdir(str(target), False)
68
+ assert code == 0
69
+ assert target.is_dir()
70
+ exit_code, msg = cmd.execute([str(target)])
71
+ assert exit_code == 1
72
+ assert "Item already exists" in msg
73
+ nested = tmp_path / "parent_dir" / "child_dir" / "leaf_dir"
74
+ exit_code, msg = cmd.execute([str(nested)])
75
+ assert exit_code == 1
76
+ assert "Parent directory does not exist" in msg
77
+ exit_code, msg = cmd.execute(["-p", str(nested)])
78
+ assert exit_code == 0
79
+ assert "Created directory" in msg
80
+ assert nested.is_dir()
81
+ exit_code, msg = cmd.execute(["--parents", str(nested)])
82
+ assert exit_code == 0
83
+
84
+
85
+ def test_native_mkdir_errors(tmp_path):
86
+ regular_file = tmp_path / "blocker.txt"
87
+ regular_file.write_text("file", encoding="utf-8")
88
+ code, _ = bridge._native.mkdir(str(regular_file / "sub"), True)
89
+ assert code == -4
90
+ cmd = handler.MkDir()
91
+ exit_code, msg = cmd.execute(["-p"])
92
+ assert exit_code == 1
93
+ assert "Directory name not specified" in msg
94
+
95
+
96
+ def test_native_touch_creates_and_updates_file(tmp_path):
97
+ target = tmp_path / "native_touch.txt"
98
+ code, _ = bridge._native.touch(str(target))
99
+ assert code == 0
100
+ assert target.exists()
101
+ cmd = handler.Touch()
102
+ exit_code, msg = cmd.execute([str(target)])
103
+ assert exit_code == 0
104
+ assert "touched successfully" in msg
105
+
106
+
107
+ def test_native_touch_errors(tmp_path):
108
+ missing_parent = tmp_path / "no_such_dir" / "file.txt"
109
+ code, _ = bridge._native.touch(str(missing_parent))
110
+ assert code == -1
111
+ cmd = handler.Touch()
112
+ exit_code, msg = cmd.execute([str(tmp_path)])
113
+ assert exit_code == 1
114
+ assert "Target is a directory, not a file" in msg
115
+
116
+
117
+ def test_native_rename_file_and_directory(tmp_path):
118
+ src = tmp_path / "old_name.txt"
119
+ src.write_text("payload", encoding="utf-8")
120
+ cmd = handler.Rename()
121
+ exit_code, msg = cmd.execute([str(src), "new_name.txt"])
122
+ assert exit_code == 0
123
+ assert "Renamed 'old_name.txt' -> 'new_name.txt'" in msg
124
+ assert not src.exists()
125
+ assert (tmp_path / "new_name.txt").read_text(encoding="utf-8") == "payload"
126
+ src_dir = tmp_path / "old_dir"
127
+ src_dir.mkdir()
128
+ exit_code, msg = cmd.execute([str(src_dir), "new_dir"])
129
+ assert exit_code == 0
130
+ assert not src_dir.exists()
131
+ assert (tmp_path / "new_dir").is_dir()
132
+
133
+
134
+ def test_native_rename_errors(tmp_path):
135
+ cmd = handler.Rename()
136
+ exit_code, msg = cmd.execute([str(tmp_path / "ghost.txt"), "other.txt"])
137
+ assert exit_code == 1
138
+ assert "not found" in msg
139
+ a = tmp_path / "a.txt"
140
+ b = tmp_path / "b.txt"
141
+ a.write_text("1", encoding="utf-8")
142
+ b.write_text("2", encoding="utf-8")
143
+ code, _ = bridge._native.rename(str(a), str(b))
144
+ assert code == -5 # ERR_EXISTS
145
+ exit_code, msg = cmd.execute([str(a), "../escape.txt"])
146
+ assert exit_code == 1
147
+ assert "Invalid file name" in msg
148
+
149
+
85
150
  def test_native_unicode_paths(tmp_path):
86
151
  unicode_dir = tmp_path / "dir_日本語"
87
- unicode_dir.mkdir()
152
+ code, _ = bridge._native.mkdir(str(unicode_dir), False)
153
+ assert code == 0
154
+ assert unicode_dir.is_dir()
88
155
  unicode_file = unicode_dir / "café_🚀.txt"
89
156
  code, _ = bridge._native.touch(str(unicode_file))
90
157
  assert code == 0
@@ -12,33 +12,16 @@ def force_legacy_backend(monkeypatch):
12
12
  monkeypatch.setattr(bridge, "has_native_support", lambda: False)
13
13
 
14
14
 
15
- def test_legacy_touch_creates_file_and_updates_timestamp(tmp_path):
16
- cmd = handler.Touch()
17
- target = tmp_path / "test.txt"
18
- code, msg = cmd.execute([str(target)])
19
- assert code == 0
20
- assert "touched successfully" in msg
21
- assert target.exists()
22
- code, msg = cmd.execute([str(target)])
23
- assert code == 0
24
- assert "touched successfully" in msg
25
-
26
-
27
- def test_legacy_touch_missing_parent_directory(tmp_path):
28
- cmd = handler.Touch()
29
- target = tmp_path / "nonexistent_dir" / "test.txt"
30
- code, msg = cmd.execute([str(target)])
31
- assert code == 1
32
- assert "File or path not found" in msg
33
-
34
-
35
- def test_legacy_touch_directory_error(tmp_path):
36
- code, _ = legacy.lgc_touch(tmp_path)
37
- assert code == -3 # ERR_IS_DIR
38
- cmd = handler.Touch()
39
- exit_code, msg = cmd.execute([str(tmp_path)])
40
- assert exit_code == 1
41
- assert "Target is a directory, not a file" in msg
15
+ def test_legacy_rename_file_and_errors(tmp_path):
16
+ src = tmp_path / "legacy_old.txt"
17
+ src.write_text("hello", encoding="utf-8")
18
+ cmd = handler.Rename()
19
+ exit_code, msg = cmd.execute([str(src), "legacy_new.txt"])
20
+ assert exit_code == 0
21
+ assert not src.exists()
22
+ assert (tmp_path / "legacy_new.txt").exists()
23
+ code, _ = legacy.lgc_rename(tmp_path / "missing.txt", tmp_path / "dst.txt")
24
+ assert code == -1 # ERR_NOT_FOUND
42
25
 
43
26
 
44
27
  def test_legacy_cat_reads_content_with_limit_and_numbers(tmp_path):
@@ -82,3 +65,62 @@ def test_legacy_dir_lists_files_and_handles_errors(tmp_path):
82
65
  code, msg = cmd.execute([str(tmp_path / "beta.txt")])
83
66
  assert code == 1
84
67
  assert "Target is not a directory" in msg
68
+
69
+
70
+ def test_legacy_mkdir_creates_and_handles_parents(tmp_path):
71
+ cmd = handler.MkDir()
72
+ target = tmp_path / "legacy_folder"
73
+ exit_code, msg = cmd.execute([str(target)])
74
+ assert exit_code == 0
75
+ assert "Created directory" in msg
76
+ assert target.is_dir()
77
+ exit_code, msg = cmd.execute([str(target)])
78
+ assert exit_code == 1
79
+ assert "Item already exists" in msg
80
+ nested = tmp_path / "parent_dir" / "child_dir"
81
+ exit_code, msg = cmd.execute([str(nested)])
82
+ assert exit_code == 1
83
+ assert "Parent directory does not exist" in msg
84
+ exit_code, msg = cmd.execute(["-p", str(nested)])
85
+ assert exit_code == 0
86
+ assert nested.is_dir()
87
+
88
+
89
+ def test_legacy_mkdir_errors(tmp_path):
90
+ regular_file = tmp_path / "blocker.txt"
91
+ regular_file.write_text("file", encoding="utf-8")
92
+ code, _ = legacy.lgc_mkdir(regular_file / "sub", parents=True)
93
+ assert code == -4 # ERR_NOT_DIR
94
+ cmd = handler.MkDir()
95
+ exit_code, msg = cmd.execute(["--parents"])
96
+ assert exit_code == 1
97
+ assert "Directory name not specified" in msg
98
+
99
+
100
+ def test_legacy_touch_creates_file_and_updates_timestamp(tmp_path):
101
+ cmd = handler.Touch()
102
+ target = tmp_path / "test.txt"
103
+ code, msg = cmd.execute([str(target)])
104
+ assert code == 0
105
+ assert "touched successfully" in msg
106
+ assert target.exists()
107
+ code, msg = cmd.execute([str(target)])
108
+ assert code == 0
109
+ assert "touched successfully" in msg
110
+
111
+
112
+ def test_legacy_touch_missing_parent_directory(tmp_path):
113
+ cmd = handler.Touch()
114
+ target = tmp_path / "nonexistent_dir" / "test.txt"
115
+ code, msg = cmd.execute([str(target)])
116
+ assert code == 1
117
+ assert "File or path not found" in msg
118
+
119
+
120
+ def test_legacy_touch_directory_error(tmp_path):
121
+ code, _ = legacy.lgc_touch(tmp_path)
122
+ assert code == -3 # ERR_IS_DIR
123
+ cmd = handler.Touch()
124
+ exit_code, msg = cmd.execute([str(tmp_path)])
125
+ assert exit_code == 1
126
+ assert "Target is a directory, not a file" in msg
@@ -3,31 +3,6 @@
3
3
  from flyshell.builtin import diskops
4
4
 
5
5
 
6
- def test_mkdir_standard_and_parents(tmp_path):
7
- cmd = diskops.MkDir()
8
- target = tmp_path / "new_folder"
9
- code, msg = cmd.execute([str(target)])
10
- assert code == 0
11
- assert target.is_dir()
12
- code, msg = cmd.execute([str(target)])
13
- assert code == 1
14
- assert "already exists" in msg
15
- nested = tmp_path / "parent" / "child"
16
- code, msg = cmd.execute(["-p", str(nested)])
17
- assert code == 0
18
- assert nested.is_dir()
19
-
20
-
21
- def test_rename_file(tmp_path):
22
- src = tmp_path / "old.txt"
23
- src.write_text("data")
24
- cmd = diskops.Rename()
25
- code, msg = cmd.execute([str(src), "new.txt"])
26
- assert code == 0
27
- assert not src.exists()
28
- assert (tmp_path / "new.txt").exists()
29
-
30
-
31
6
  def test_copy_file_and_directory(tmp_path):
32
7
  src_file = tmp_path / "source.txt"
33
8
  src_file.write_text("payload")
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