flyshell 1.3.8__tar.gz → 1.3.10__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.3.8/src/flyshell.egg-info → flyshell-1.3.10}/PKG-INFO +1 -1
- flyshell-1.3.10/c_src/diskops/diskops.c +100 -0
- flyshell-1.3.10/c_src/diskops/posix/dir.c +71 -0
- flyshell-1.3.10/c_src/diskops/posix/touch.c +35 -0
- flyshell-1.3.10/c_src/diskops/shared/dir_types.c +16 -0
- flyshell-1.3.10/c_src/diskops/shared/dir_types.h +21 -0
- flyshell-1.3.10/c_src/diskops/win32/dir.c +65 -0
- flyshell-1.3.10/c_src/diskops/win32/touch.c +54 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/setup.py +5 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/builtin/diskops.py +0 -65
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/constants.py +3 -2
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/core/directory.py +2 -2
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/native/diskops_handler.py +49 -1
- flyshell-1.3.10/src/flyshell/native/legacy/diskops.py +65 -0
- flyshell-1.3.10/src/flyshell/startup/__init__.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10/src/flyshell.egg-info}/PKG-INFO +1 -1
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell.egg-info/SOURCES.txt +7 -0
- flyshell-1.3.8/c_src/diskops/diskops.c +0 -57
- flyshell-1.3.8/src/flyshell/native/legacy/diskops.py +0 -22
- {flyshell-1.3.8 → flyshell-1.3.10}/LICENSE +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/MANIFEST.in +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/README.md +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/c_src/diskops/posix/cat.c +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/c_src/diskops/shared/native_errors.h +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/c_src/diskops/win32/cat.c +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/pyproject.toml +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/setup.cfg +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/__init__.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/abstract/__init__.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/abstract/base_cmd.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/abstract/base_plugin.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/abstract/parent_cmd.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/accounts/__init__.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/accounts/auth.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/bin/__init__.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/builtin/__init__.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/builtin/fs.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/builtin/pkg.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/builtin/system.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/builtin/utils.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/core/__init__.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/core/console.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/core/data.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/main.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/native/__init__.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/native/diskops_bridge.py +0 -0
- {flyshell-1.3.8/src/flyshell/startup → flyshell-1.3.10/src/flyshell/native/legacy}/__init__.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/startup/deps.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/startup/env.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell/startup/loader.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell.egg-info/dependency_links.txt +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell.egg-info/entry_points.txt +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell.egg-info/requires.txt +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/src/flyshell.egg-info/top_level.txt +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/tests/test_auth.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/tests/test_data.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/tests/test_deps.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/tests/test_directory.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/tests/test_diskops.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/tests/test_env.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/tests/test_fs.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/tests/test_loader.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/tests/test_pkg.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/tests/test_security.py +0 -0
- {flyshell-1.3.8 → flyshell-1.3.10}/tests/test_utils.py +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// c_src/diskops/diskops.c
|
|
2
|
+
|
|
3
|
+
#define PY_SSIZE_T_CLEAN
|
|
4
|
+
#include <Python.h>
|
|
5
|
+
#include "shared/native_errors.h"
|
|
6
|
+
#include "shared/dir_types.h"
|
|
7
|
+
|
|
8
|
+
Result cat(const char* path, char** out_buf, size_t* out_size);
|
|
9
|
+
|
|
10
|
+
Result touch(const char* path);
|
|
11
|
+
|
|
12
|
+
Result list_dir(const char* path, DirList* out_list);
|
|
13
|
+
|
|
14
|
+
static PyObject* method_ping(PyObject* self, PyObject* args) {
|
|
15
|
+
return PyLong_FromLong(42);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
static PyObject* method_cat(PyObject* self, PyObject* args) {
|
|
19
|
+
const char* path;
|
|
20
|
+
if (!PyArg_ParseTuple(args, "s", &path)) {
|
|
21
|
+
return NULL;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
char* buf = NULL;
|
|
25
|
+
size_t size = 0;
|
|
26
|
+
Result res = cat(path, &buf, &size);
|
|
27
|
+
|
|
28
|
+
if (res != SUCCESS) {
|
|
29
|
+
return Py_BuildValue("(is)", (int)res, "");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
PyObject* content = PyUnicode_FromStringAndSize(buf, size);
|
|
33
|
+
free(buf);
|
|
34
|
+
|
|
35
|
+
if (!content) {
|
|
36
|
+
PyErr_Clear();
|
|
37
|
+
return Py_BuildValue("(is)", (int)ERR_DECODE, "");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
PyObject* ret = Py_BuildValue("(iN)", (int)SUCCESS, content);
|
|
41
|
+
return ret;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static PyObject* method_touch(PyObject* self, PyObject* args) {
|
|
45
|
+
const char* path;
|
|
46
|
+
if (!PyArg_ParseTuple(args, "s", &path)) {
|
|
47
|
+
return NULL;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Result res = touch(path);
|
|
51
|
+
return Py_BuildValue("(is)", (int)res, "");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static PyObject* method_dir(PyObject* self, PyObject* args) {
|
|
55
|
+
const char* path;
|
|
56
|
+
if (!PyArg_ParseTuple(args, "s", &path)) {
|
|
57
|
+
return NULL;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
DirList dir_list;
|
|
61
|
+
Result res = list_dir(path, &dir_list);
|
|
62
|
+
if (res != SUCCESS) {
|
|
63
|
+
return Py_BuildValue("(i[])", (int)res);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
PyObject* py_list = PyList_New(dir_list.count);
|
|
67
|
+
if (!py_list) {
|
|
68
|
+
free_dir_list(&dir_list);
|
|
69
|
+
return Py_BuildValue("(i[])", (int)ERR_IO);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
for (size_t i = 0; i < dir_list.count; ++i) {
|
|
73
|
+
PyObject* item = Py_BuildValue("(sO)", dir_list.entries[i].name,
|
|
74
|
+
dir_list.entries[i].is_dir ? Py_True : Py_False);
|
|
75
|
+
PyList_SET_ITEM(py_list, i, item);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
free_dir_list(&dir_list);
|
|
79
|
+
return Py_BuildValue("(iN)", (int)SUCCESS, py_list);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static PyMethodDef DiskopsMethods[] = {
|
|
83
|
+
{"ping", method_ping, METH_NOARGS, "Health check ping."},
|
|
84
|
+
{"cat", method_cat, METH_VARARGS, "Read file content natively."},
|
|
85
|
+
{"touch", method_touch, METH_VARARGS, "Touch or create file natively."},
|
|
86
|
+
{"dir", method_dir, METH_VARARGS, "List directory contents natively."},
|
|
87
|
+
{NULL, NULL, 0, NULL},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
static struct PyModuleDef diskopsmodule = {
|
|
91
|
+
PyModuleDef_HEAD_INIT,
|
|
92
|
+
"_native_diskops",
|
|
93
|
+
"Flyshell native disk operations.",
|
|
94
|
+
-1,
|
|
95
|
+
DiskopsMethods
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
PyMODINIT_FUNC PyInit__native_diskops(void) {
|
|
99
|
+
return PyModule_Create(&diskopsmodule);
|
|
100
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// c_src/diskops/posix/dir.c
|
|
2
|
+
|
|
3
|
+
#define _POSIX_C_SOURCE 200809L
|
|
4
|
+
#define _GNU_SOURCE
|
|
5
|
+
|
|
6
|
+
#include <dirent.h>
|
|
7
|
+
#include <sys/stat.h>
|
|
8
|
+
#include <stdlib.h>
|
|
9
|
+
#include <string.h>
|
|
10
|
+
#include <errno.h>
|
|
11
|
+
#include "../shared/native_errors.h"
|
|
12
|
+
#include "../shared/dir_types.h"
|
|
13
|
+
|
|
14
|
+
Result list_dir(const char* path, DirList* out_list) {
|
|
15
|
+
if (!path || path[0] == '\0' || !out_list) {
|
|
16
|
+
return ERR_INVALID_PATH;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
out_list->entries = NULL;
|
|
20
|
+
out_list->count = 0;
|
|
21
|
+
|
|
22
|
+
DIR* dir = opendir(path);
|
|
23
|
+
if (!dir) {
|
|
24
|
+
return map_posix_errno(errno);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
size_t capacity = 16;
|
|
28
|
+
out_list->entries = (DirEntry*)malloc(capacity * sizeof(DirEntry));
|
|
29
|
+
if (!out_list->entries) {
|
|
30
|
+
closedir(dir);
|
|
31
|
+
return ERR_IO;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
struct dirent* entry;
|
|
35
|
+
while ((entry = readdir(dir)) != NULL) {
|
|
36
|
+
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (out_list->count >= capacity) {
|
|
41
|
+
capacity *= 2;
|
|
42
|
+
DirEntry* resized = (DirEntry*)realloc(out_list->entries, capacity * sizeof(DirEntry));
|
|
43
|
+
if (!resized) {
|
|
44
|
+
closedir(dir);
|
|
45
|
+
free_dir_list(out_list);
|
|
46
|
+
return ERR_IO;
|
|
47
|
+
}
|
|
48
|
+
out_list->entries = resized;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
bool is_dir = false;
|
|
52
|
+
#ifdef _DIRENT_HAVE_D_TYPE
|
|
53
|
+
if (entry->d_type != DT_UNKNOWN) {
|
|
54
|
+
is_dir = (entry->d_type == DT_DIR);
|
|
55
|
+
} else
|
|
56
|
+
#endif
|
|
57
|
+
{
|
|
58
|
+
struct stat st;
|
|
59
|
+
if (fstatat(dirfd(dir), entry->d_name, &st, 0) == 0) {
|
|
60
|
+
is_dir = S_ISDIR(st.st_mode);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
out_list->entries[out_list->count].name = strdup(entry->d_name);
|
|
65
|
+
out_list->entries[out_list->count].is_dir = is_dir;
|
|
66
|
+
out_list->count++;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
closedir(dir);
|
|
70
|
+
return SUCCESS;
|
|
71
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// c_src/diskops/posix/touch.c
|
|
2
|
+
|
|
3
|
+
#define _POSIX_C_SOURCE 200809L
|
|
4
|
+
#define _GNU_SOURCE
|
|
5
|
+
|
|
6
|
+
#include <fcntl.h>
|
|
7
|
+
#include <sys/stat.h>
|
|
8
|
+
#include <unistd.h>
|
|
9
|
+
#include <errno.h>
|
|
10
|
+
#include "../shared/native_errors.h"
|
|
11
|
+
|
|
12
|
+
Result touch(const char* path) {
|
|
13
|
+
if (!path || path[0] == '\0') {
|
|
14
|
+
return ERR_INVALID_PATH;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
struct stat st;
|
|
18
|
+
if (stat(path, &st) == 0) {
|
|
19
|
+
if (S_ISDIR(st.st_mode)) {
|
|
20
|
+
return ERR_IS_DIR;
|
|
21
|
+
}
|
|
22
|
+
if (utimensat(AT_FDCWD, path, NULL, 0) != 0) {
|
|
23
|
+
return map_posix_errno(errno);
|
|
24
|
+
}
|
|
25
|
+
return SUCCESS;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
int fd = open(path, O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY, 0666);
|
|
29
|
+
if (fd < 0) {
|
|
30
|
+
return map_posix_errno(errno);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
close(fd);
|
|
34
|
+
return SUCCESS;
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// c_src/diskops/shared/dir_types.c
|
|
2
|
+
|
|
3
|
+
#include <stdlib.h>
|
|
4
|
+
#include "dir_types.h"
|
|
5
|
+
|
|
6
|
+
void free_dir_list(DirList* list) {
|
|
7
|
+
if (!list) return;
|
|
8
|
+
if (list->entries) {
|
|
9
|
+
for (size_t i = 0; i < list ->count; ++i) {
|
|
10
|
+
free(list->entries[i].name);
|
|
11
|
+
}
|
|
12
|
+
free(list->entries);
|
|
13
|
+
list->entries = NULL;
|
|
14
|
+
}
|
|
15
|
+
list->count = 0;
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// c_src/diskops/shared/dir_types.h
|
|
2
|
+
|
|
3
|
+
#ifndef DIR_TYPES_H
|
|
4
|
+
#define DIR_TYPES_H
|
|
5
|
+
|
|
6
|
+
#include <stdbool.h>
|
|
7
|
+
#include <stddef.h>
|
|
8
|
+
|
|
9
|
+
typedef struct {
|
|
10
|
+
char* name;
|
|
11
|
+
bool is_dir;
|
|
12
|
+
} DirEntry;
|
|
13
|
+
|
|
14
|
+
typedef struct {
|
|
15
|
+
DirEntry* entries;
|
|
16
|
+
size_t count;
|
|
17
|
+
} DirList;
|
|
18
|
+
|
|
19
|
+
void free_dir_list(DirList* list);
|
|
20
|
+
|
|
21
|
+
#endif /* DIR_TYPES_H */
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// c_src/diskops/win32/dir.c
|
|
2
|
+
|
|
3
|
+
#include <windows.h>
|
|
4
|
+
#include <stdio.h>
|
|
5
|
+
#include <stdlib.h>
|
|
6
|
+
#include <string.h>
|
|
7
|
+
#include "../shared/native_errors.h"
|
|
8
|
+
#include "../shared/dir_types.h"
|
|
9
|
+
|
|
10
|
+
Result list_dir(const char* path, DirList* out_list) {
|
|
11
|
+
if (!path || path[0] == '\0' || !out_list) {
|
|
12
|
+
return ERR_INVALID_PATH;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
out_list->entries = NULL;
|
|
16
|
+
out_list->count = 0;
|
|
17
|
+
|
|
18
|
+
char search_pattern[MAX_PATH];
|
|
19
|
+
snprintf(search_pattern, sizeof(search_pattern), "%s\\*", path);
|
|
20
|
+
|
|
21
|
+
WIN32_FIND_DATAA find_data;
|
|
22
|
+
HANDLE h_find = FindFirstFileA(search_pattern, &find_data);
|
|
23
|
+
if (h_find == INVALID_HANDLE_VALUE) {
|
|
24
|
+
return map_win32_error(GetLastError());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
size_t capacity = 16;
|
|
28
|
+
out_list->entries = (DirEntry*)malloc(capacity * sizeof(DirEntry));
|
|
29
|
+
if (!out_list->entries) {
|
|
30
|
+
FindClose(h_find);
|
|
31
|
+
return ERR_IO;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
do {
|
|
35
|
+
if (strcmp(find_data.cFileName, ".") == 0 || strcmp(find_data.cFileName, "..") == 0) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (out_list->count >= capacity) {
|
|
40
|
+
capacity *= 2;
|
|
41
|
+
DirEntry* resized = (DirEntry*)realloc(out_list->entries, capacity * sizeof(DirEntry));
|
|
42
|
+
if (!resized) {
|
|
43
|
+
FindClose(h_find);
|
|
44
|
+
free_dir_list(out_list);
|
|
45
|
+
return ERR_IO;
|
|
46
|
+
}
|
|
47
|
+
out_list->entries = resized;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
bool is_dir = (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
|
51
|
+
out_list->entries[out_list->count].name = _strdup(find_data.cFileName);
|
|
52
|
+
out_list->entries[out_list->count].is_dir = is_dir;
|
|
53
|
+
out_list->count++;
|
|
54
|
+
} while (FindNextFileA(h_find, &find_data) != 0);
|
|
55
|
+
|
|
56
|
+
DWORD err = GetLastError();
|
|
57
|
+
FindClose(h_find);
|
|
58
|
+
|
|
59
|
+
if (err != ERROR_NO_MORE_FILES && err != ERROR_SUCCESS) {
|
|
60
|
+
free_dir_list(out_list);
|
|
61
|
+
return map_win32_error(err);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return SUCCESS;
|
|
65
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// c_src/diskops/win32/touch.c
|
|
2
|
+
|
|
3
|
+
#include <windows.h>
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
#include "../shared/native_errors.h"
|
|
6
|
+
|
|
7
|
+
Result touch(const char* path) {
|
|
8
|
+
if (!path || path[0] == '\0') {
|
|
9
|
+
return ERR_INVALID_PATH;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
int wlen = MultiByteToWideChar(CP_UTF8, 0, path, -1, NULL, 0);
|
|
13
|
+
if (wlen <= 0) {
|
|
14
|
+
return ERR_INVALID_PATH;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
wchar_t* wpath = (wchar_t*)malloc(wlen * sizeof(wchar_t));
|
|
18
|
+
if (!wpath) {
|
|
19
|
+
return ERR_IO;
|
|
20
|
+
}
|
|
21
|
+
MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, wlen);
|
|
22
|
+
|
|
23
|
+
DWORD attrs = GetFileAttributesW(wpath);
|
|
24
|
+
if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) {
|
|
25
|
+
free(wpath);
|
|
26
|
+
return ERR_IS_DIR;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
HANDLE hFile = CreateFileW(
|
|
30
|
+
wpath,
|
|
31
|
+
FILE_WRITE_ATTRIBUTES,
|
|
32
|
+
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
33
|
+
NULL,
|
|
34
|
+
OPEN_ALWAYS,
|
|
35
|
+
FILE_ATTRIBUTE_NORMAL,
|
|
36
|
+
NULL
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (hFile == INVALID_HANDLE_VALUE) {
|
|
40
|
+
DWORD err = GetLastError();
|
|
41
|
+
free(wpath);
|
|
42
|
+
return map_win32_error(err);
|
|
43
|
+
}
|
|
44
|
+
free(wpath);
|
|
45
|
+
|
|
46
|
+
FILETIME ft;
|
|
47
|
+
SYSTEMTIME st;
|
|
48
|
+
GetSystemTime(&st);
|
|
49
|
+
SystemTimeToFileTime(&st, &ft);
|
|
50
|
+
SetFileTime(hFile, NULL, &ft, &ft);
|
|
51
|
+
|
|
52
|
+
CloseHandle(hFile);
|
|
53
|
+
return SUCCESS;
|
|
54
|
+
}
|
|
@@ -5,12 +5,17 @@ import sys
|
|
|
5
5
|
|
|
6
6
|
sources = [
|
|
7
7
|
"c_src/diskops/diskops.c",
|
|
8
|
+
"c_src/diskops/shared/dir_types.c",
|
|
8
9
|
]
|
|
9
10
|
|
|
10
11
|
if sys.platform == "win32":
|
|
11
12
|
sources.append("c_src/diskops/win32/cat.c")
|
|
13
|
+
sources.append("c_src/diskops/win32/dir.c")
|
|
14
|
+
sources.append("c_src/diskops/win32/touch.c")
|
|
12
15
|
else:
|
|
13
16
|
sources.append("c_src/diskops/posix/cat.c")
|
|
17
|
+
sources.append("c_src/diskops/posix/dir.c")
|
|
18
|
+
sources.append("c_src/diskops/posix/touch.c")
|
|
14
19
|
|
|
15
20
|
native_diskops = Extension(
|
|
16
21
|
name="flyshell.bin._native_diskops",
|
|
@@ -71,29 +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 Dir(BaseCmd):
|
|
75
|
-
name = "dir"
|
|
76
|
-
description = "List all files in the current working directory"
|
|
77
|
-
min_args = 0
|
|
78
|
-
options = None
|
|
79
|
-
aliases = ["ls"]
|
|
80
|
-
|
|
81
|
-
def execute(self, args):
|
|
82
|
-
try:
|
|
83
|
-
current_path = os.getcwd()
|
|
84
|
-
items = os.listdir(current_path)
|
|
85
|
-
lines = [f"\nDirectory: '{current_path}'"]
|
|
86
|
-
for item in items:
|
|
87
|
-
if os.path.isdir(os.path.join(current_path, item)):
|
|
88
|
-
lines.append(f"[DIR] {item}/")
|
|
89
|
-
else:
|
|
90
|
-
lines.append(f"[FILE] {item}")
|
|
91
|
-
lines.append(f"\nTotal items in directory: {len(items)}\n")
|
|
92
|
-
return (0, "\n".join(lines))
|
|
93
|
-
except Exception as e:
|
|
94
|
-
return (1, f"\nSystem Error: Unable to list directory ({e})\n")
|
|
95
|
-
|
|
96
|
-
|
|
97
74
|
class MkDir(BaseCmd):
|
|
98
75
|
name = "mkdir"
|
|
99
76
|
description = "Create a new directory from the current working directory"
|
|
@@ -446,45 +423,3 @@ class RmDir(BaseCmd):
|
|
|
446
423
|
1,
|
|
447
424
|
f"\nSystem Error: Unexpected error removing '{raw_target}' ({e})\n",
|
|
448
425
|
)
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
class Touch(BaseCmd):
|
|
452
|
-
name = "touch"
|
|
453
|
-
description = "Create a new empty file or update timestamps of an existing file"
|
|
454
|
-
min_args = 1
|
|
455
|
-
options = "Target file"
|
|
456
|
-
aliases = []
|
|
457
|
-
|
|
458
|
-
def execute(self, args):
|
|
459
|
-
raw_target = " ".join(args).strip("\"'")
|
|
460
|
-
target_path = Path(raw_target).expanduser().resolve()
|
|
461
|
-
if target_path.is_dir():
|
|
462
|
-
return (
|
|
463
|
-
1,
|
|
464
|
-
f"\nCommand Error: '{raw_target}' is a directory, not a file.\n",
|
|
465
|
-
)
|
|
466
|
-
if not target_path.parent.exists():
|
|
467
|
-
return (
|
|
468
|
-
1,
|
|
469
|
-
f"\nSystem Error: Cannot create file '{raw_target}'. Parent directory does not exist.\n",
|
|
470
|
-
)
|
|
471
|
-
try:
|
|
472
|
-
if target_path.exists():
|
|
473
|
-
target_path.touch()
|
|
474
|
-
return (
|
|
475
|
-
0,
|
|
476
|
-
f"\nSUCCESS! Updated timestamp for existing file '{raw_target}'\n",
|
|
477
|
-
)
|
|
478
|
-
else:
|
|
479
|
-
target_path.touch(exist_ok=False)
|
|
480
|
-
return (0, f"\nSUCCESS! Created file '{raw_target}'\n")
|
|
481
|
-
except PermissionError:
|
|
482
|
-
return (
|
|
483
|
-
1,
|
|
484
|
-
f"\nSystem Error: Permission denied. Cannot access '{raw_target}'.\n",
|
|
485
|
-
)
|
|
486
|
-
except Exception as e:
|
|
487
|
-
return (
|
|
488
|
-
1,
|
|
489
|
-
f"\nSystem Error: Failed to touch file '{raw_target}' ({e})\n",
|
|
490
|
-
)
|
|
@@ -5,8 +5,8 @@ import os
|
|
|
5
5
|
import platform
|
|
6
6
|
import time
|
|
7
7
|
|
|
8
|
-
BUILD =
|
|
9
|
-
VERSION = "1.3.
|
|
8
|
+
BUILD = 150
|
|
9
|
+
VERSION = "1.3.10"
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
def _resolve_app_dir() -> Path:
|
|
@@ -73,6 +73,7 @@ REQUIRED_COMPONENTS = [
|
|
|
73
73
|
"main.py",
|
|
74
74
|
"native",
|
|
75
75
|
"native/__init__.py",
|
|
76
|
+
"native/legacy/__init__.py",
|
|
76
77
|
"native/legacy/diskops.py",
|
|
77
78
|
"native/diskops_bridge.py",
|
|
78
79
|
"native/diskops_handler.py",
|
|
@@ -59,7 +59,7 @@ INSTALLED_COMMANDS: list[BaseCmd] = [
|
|
|
59
59
|
Cmds(),
|
|
60
60
|
utils.Clear(),
|
|
61
61
|
diskops_legacy.Copy(),
|
|
62
|
-
|
|
62
|
+
diskops.Dir(),
|
|
63
63
|
utils.Echo(),
|
|
64
64
|
fs.Fs(),
|
|
65
65
|
utils.History(),
|
|
@@ -75,7 +75,7 @@ INSTALLED_COMMANDS: list[BaseCmd] = [
|
|
|
75
75
|
diskops_legacy.RmDir(),
|
|
76
76
|
utils.Sleep(),
|
|
77
77
|
system.SysExe(),
|
|
78
|
-
|
|
78
|
+
diskops.Touch(),
|
|
79
79
|
]
|
|
80
80
|
|
|
81
81
|
COMMAND_REGISTRY: dict[str, BaseCmd] = {}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# src/flyshell/native/diskops_handler.py
|
|
2
2
|
|
|
3
|
-
from pathlib import Path
|
|
4
3
|
from flyshell.abstract.base_cmd import BaseCmd
|
|
5
4
|
from flyshell.native import diskops_bridge as bridge
|
|
6
5
|
from flyshell.native.legacy import diskops as legacy
|
|
7
6
|
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import os
|
|
9
|
+
|
|
8
10
|
|
|
9
11
|
class Cat(BaseCmd):
|
|
10
12
|
name = "cat"
|
|
@@ -60,3 +62,49 @@ class Cat(BaseCmd):
|
|
|
60
62
|
output_lines.append(clean_line)
|
|
61
63
|
output_lines.append(f"\nEnd of '{target_path.name}'\n")
|
|
62
64
|
return (0, "\n".join(output_lines))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class Dir(BaseCmd):
|
|
68
|
+
name = "dir"
|
|
69
|
+
description = "List all files in the current working directory"
|
|
70
|
+
min_args = 0
|
|
71
|
+
options = None
|
|
72
|
+
aliases = ["ls"]
|
|
73
|
+
|
|
74
|
+
def execute(self, args):
|
|
75
|
+
target_str = args[0].strip("\"'") if args else os.getcwd()
|
|
76
|
+
target_path = Path(target_str).expanduser().resolve()
|
|
77
|
+
if bridge.has_native_support() and hasattr(bridge._native, "dir"):
|
|
78
|
+
code, items = bridge._native.dir(str(target_path))
|
|
79
|
+
else:
|
|
80
|
+
code, items = legacy.lgc_dir(target_path)
|
|
81
|
+
if code != 0:
|
|
82
|
+
return bridge.translate_error(code, str(target_path))
|
|
83
|
+
lines = [f"\nDirectory: '{target_path}'"]
|
|
84
|
+
for name, is_dir in items:
|
|
85
|
+
if is_dir:
|
|
86
|
+
lines.append(f"[DIR] {name}/")
|
|
87
|
+
else:
|
|
88
|
+
lines.append(f"[FILE] {name}")
|
|
89
|
+
lines.append(f"\nTotal items in directory: {len(items)}\n")
|
|
90
|
+
return (0, "\n".join(lines))
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class Touch(BaseCmd):
|
|
94
|
+
name = "touch"
|
|
95
|
+
description = "Create an empty file or update existing file timestamps"
|
|
96
|
+
min_args = 1
|
|
97
|
+
options = "Target file"
|
|
98
|
+
|
|
99
|
+
def execute(self, args):
|
|
100
|
+
if not args:
|
|
101
|
+
return (1, "\nCommand Error: Target file not specified.\n")
|
|
102
|
+
raw_target = " ".join(args).strip("\"'")
|
|
103
|
+
target_path = Path(raw_target).expanduser().resolve()
|
|
104
|
+
if bridge.has_native_support() and hasattr(bridge._native, "touch"):
|
|
105
|
+
code, _ = bridge._native.touch(str(target_path))
|
|
106
|
+
else:
|
|
107
|
+
code, _ = legacy.lgc_touch(target_path)
|
|
108
|
+
if code != 0:
|
|
109
|
+
return bridge.translate_error(code, raw_target)
|
|
110
|
+
return (0, f"\nSUCCESS! File '{raw_target}' touched successfully.\n")
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# src/flyshell/native/legacy/diskops.py
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def lgc_cat(target_path: Path) -> tuple[int, str]:
|
|
8
|
+
if not target_path.exists():
|
|
9
|
+
return (-1, "") # ERR_NOT_FOUND
|
|
10
|
+
if target_path.is_dir():
|
|
11
|
+
return (-3, "") # ERR_IS_DIR
|
|
12
|
+
try:
|
|
13
|
+
with open(target_path, "r", encoding="utf-8", errors="replace") as f:
|
|
14
|
+
content = f.read()
|
|
15
|
+
if len(content) == 0:
|
|
16
|
+
return (-8, "") # ERR_EMPTY
|
|
17
|
+
return (0, content) # SUCCESS
|
|
18
|
+
except PermissionError:
|
|
19
|
+
return (-2, "") # ERR_PERMISSION
|
|
20
|
+
except UnicodeDecodeError:
|
|
21
|
+
return (-14, "") # ERR_DECODE
|
|
22
|
+
except Exception:
|
|
23
|
+
return (-13, "") # ERR_IO
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def lgc_dir(target_path: Path) -> tuple[int, list[tuple[str, bool]]]:
|
|
27
|
+
if not target_path.exists():
|
|
28
|
+
return (-1, []) # ERR_NOT_FOUND
|
|
29
|
+
if not target_path.is_dir():
|
|
30
|
+
return (-4, []) # ERR_NOT_DIR
|
|
31
|
+
try:
|
|
32
|
+
entries: list[tuple[str, bool]] = []
|
|
33
|
+
with os.scandir(target_path) as it:
|
|
34
|
+
for entry in it:
|
|
35
|
+
try:
|
|
36
|
+
entries.append((entry.name, entry.is_dir()))
|
|
37
|
+
except OSError:
|
|
38
|
+
entries.append((entry.name, False))
|
|
39
|
+
return (0, entries) # SUCCESS
|
|
40
|
+
except PermissionError:
|
|
41
|
+
return (-2, []) # ERR_PERMISSION
|
|
42
|
+
except OSError as e:
|
|
43
|
+
if getattr(e, "errno", None) == 20:
|
|
44
|
+
return (-4, []) # ERR_NOT_DIR
|
|
45
|
+
return (-13, []) # ERR_IO
|
|
46
|
+
except Exception:
|
|
47
|
+
return (-99, []) # ERR_UNKNOWN
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def lgc_touch(target_path: Path) -> tuple[int, str]:
|
|
51
|
+
if target_path.is_dir():
|
|
52
|
+
return (-3, "") # ERR_IS_DIR
|
|
53
|
+
try:
|
|
54
|
+
target_path.touch(exist_ok=True)
|
|
55
|
+
return (0, "") # SUCCESS
|
|
56
|
+
except PermissionError:
|
|
57
|
+
return (-2, "") # ERR_PERMISSION
|
|
58
|
+
except FileNotFoundError:
|
|
59
|
+
return (-1, "") # ERR_NOT_FOUND
|
|
60
|
+
except OSError as e:
|
|
61
|
+
if getattr(e, "errno", None) == 28:
|
|
62
|
+
return (-12, "") # ERR_NO_SPACE
|
|
63
|
+
return (-13, "") # ERR_IO
|
|
64
|
+
except Exception:
|
|
65
|
+
return (-99, "") # ERR_UNKNOWN
|
|
File without changes
|
|
@@ -5,8 +5,14 @@ pyproject.toml
|
|
|
5
5
|
setup.py
|
|
6
6
|
c_src/diskops/diskops.c
|
|
7
7
|
c_src/diskops/posix/cat.c
|
|
8
|
+
c_src/diskops/posix/dir.c
|
|
9
|
+
c_src/diskops/posix/touch.c
|
|
10
|
+
c_src/diskops/shared/dir_types.c
|
|
11
|
+
c_src/diskops/shared/dir_types.h
|
|
8
12
|
c_src/diskops/shared/native_errors.h
|
|
9
13
|
c_src/diskops/win32/cat.c
|
|
14
|
+
c_src/diskops/win32/dir.c
|
|
15
|
+
c_src/diskops/win32/touch.c
|
|
10
16
|
src/flyshell/__init__.py
|
|
11
17
|
src/flyshell/constants.py
|
|
12
18
|
src/flyshell/main.py
|
|
@@ -36,6 +42,7 @@ src/flyshell/core/directory.py
|
|
|
36
42
|
src/flyshell/native/__init__.py
|
|
37
43
|
src/flyshell/native/diskops_bridge.py
|
|
38
44
|
src/flyshell/native/diskops_handler.py
|
|
45
|
+
src/flyshell/native/legacy/__init__.py
|
|
39
46
|
src/flyshell/native/legacy/diskops.py
|
|
40
47
|
src/flyshell/startup/__init__.py
|
|
41
48
|
src/flyshell/startup/deps.py
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// c_src/diskops/diskops.c
|
|
2
|
-
|
|
3
|
-
#define PY_SSIZE_T_CLEAN
|
|
4
|
-
#include <Python.h>
|
|
5
|
-
#include "shared/native_errors.h"
|
|
6
|
-
|
|
7
|
-
/* Prototype declared in both posix/cat.c and win32/cat.c */
|
|
8
|
-
Result cat(const char* path, char** out_buf, size_t* out_size);
|
|
9
|
-
|
|
10
|
-
static PyObject* method_ping(PyObject* self, PyObject* args) {
|
|
11
|
-
return PyLong_FromLong(42);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
static PyObject* method_cat(PyObject* self, PyObject* args) {
|
|
15
|
-
const char* path;
|
|
16
|
-
if (!PyArg_ParseTuple(args, "s", &path)) {
|
|
17
|
-
return NULL;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
char* buf = NULL;
|
|
21
|
-
size_t size = 0;
|
|
22
|
-
Result res = cat(path, &buf, &size);
|
|
23
|
-
|
|
24
|
-
if (res != SUCCESS) {
|
|
25
|
-
return Py_BuildValue("(is)", (int)res, "");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/* Convert C buffer to Python unicode string */
|
|
29
|
-
PyObject* content = PyUnicode_FromStringAndSize(buf, size);
|
|
30
|
-
free(buf);
|
|
31
|
-
|
|
32
|
-
if (!content) {
|
|
33
|
-
PyErr_Clear();
|
|
34
|
-
return Py_BuildValue("(is)", (int)ERR_DECODE, "");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
PyObject* ret = Py_BuildValue("(iN)", (int)SUCCESS, content);
|
|
38
|
-
return ret;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
static PyMethodDef DiskopsMethods[] = {
|
|
42
|
-
{"ping", method_ping, METH_NOARGS, "Health check ping."},
|
|
43
|
-
{"cat", method_cat, METH_VARARGS, "Read file content natively."},
|
|
44
|
-
{NULL, NULL, 0, NULL}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
static struct PyModuleDef diskopsmodule = {
|
|
48
|
-
PyModuleDef_HEAD_INIT,
|
|
49
|
-
"_native_diskops",
|
|
50
|
-
"Flyshell native disk operations.",
|
|
51
|
-
-1,
|
|
52
|
-
DiskopsMethods
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
PyMODINIT_FUNC PyInit__native_diskops(void) {
|
|
56
|
-
return PyModule_Create(&diskopsmodule);
|
|
57
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# src/flyshell/native/legacy/diskops.py
|
|
2
|
-
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def lgc_cat(target_path: Path) -> tuple[int, str]:
|
|
7
|
-
if not target_path.exists():
|
|
8
|
-
return (-1, "") # ERR_NOT_FOUND
|
|
9
|
-
if target_path.is_dir():
|
|
10
|
-
return (-3, "") # ERR_IS_DIR
|
|
11
|
-
try:
|
|
12
|
-
with open(target_path, "r", encoding="utf-8", errors="replace") as f:
|
|
13
|
-
content = f.read()
|
|
14
|
-
if len(content) == 0:
|
|
15
|
-
return (-8, "") # ERR_EMPTY
|
|
16
|
-
return (0, content) # SUCCESS
|
|
17
|
-
except PermissionError:
|
|
18
|
-
return (-2, "") # ERR_PERMISSION
|
|
19
|
-
except UnicodeDecodeError:
|
|
20
|
-
return (-14, "") # ERR_DECODE
|
|
21
|
-
except Exception:
|
|
22
|
-
return (-13, "") # ERR_IO
|
|
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
|
{flyshell-1.3.8/src/flyshell/startup → flyshell-1.3.10/src/flyshell/native/legacy}/__init__.py
RENAMED
|
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
|