fix: various bug fixes in desktop components
This commit is contained in:
@@ -8,6 +8,19 @@
|
||||
|
||||
namespace filemanager {
|
||||
|
||||
static bool path_is_same_or_descendant(const char* path, const char* root) {
|
||||
if (!path || !root) return false;
|
||||
|
||||
int root_len = montauk::slen(root);
|
||||
while (root_len > 0 && root[root_len - 1] == '/') root_len--;
|
||||
if (root_len <= 0) return false;
|
||||
|
||||
for (int i = 0; i < root_len; i++) {
|
||||
if (path[i] == '\0' || path[i] != root[i]) return false;
|
||||
}
|
||||
return path[root_len] == '\0' || path[root_len] == '/';
|
||||
}
|
||||
|
||||
void filemanager_do_copy(FileManagerState* fm) {
|
||||
if (fm->selected < 0 || fm->selected >= fm->entry_count) return;
|
||||
if (filemanager_is_computer_view(fm) || filemanager_is_virtual_view(fm) ||
|
||||
@@ -36,11 +49,13 @@ void filemanager_do_paste(FileManagerState* fm) {
|
||||
const char* basename = path_basename(fm->clipboard_path);
|
||||
char dst[512];
|
||||
filemanager_build_fullpath(dst, 512, fm->current_path, basename);
|
||||
if (montauk::streq(dst, fm->clipboard_path)) return;
|
||||
|
||||
// Check if source is a directory by trying to readdir it
|
||||
const char* probe[1];
|
||||
int probe_count = montauk::readdir(fm->clipboard_path, probe, 1);
|
||||
bool src_is_dir = (probe_count >= 0);
|
||||
if (src_is_dir && path_is_same_or_descendant(dst, fm->clipboard_path)) return;
|
||||
|
||||
bool ok;
|
||||
if (src_is_dir)
|
||||
|
||||
Reference in New Issue
Block a user