Fix same-window folder drop guard
This commit is contained in:
+25
-3
@@ -892,11 +892,18 @@ async function finishItemPointerDrag(event, move, up) {
|
||||
}
|
||||
|
||||
try {
|
||||
const destination = `${target.path.replace(/\/$/, '')}/${drag.name}`;
|
||||
if (destination === drag.path) {
|
||||
const destination = joinPath(target.path, drag.name);
|
||||
recordDebug('pointer.destination', {
|
||||
source: drag.path,
|
||||
targetPath: target.path,
|
||||
destination,
|
||||
targetIsRow: Boolean(target.row),
|
||||
copy: event.altKey
|
||||
});
|
||||
if (destination === drag.path || target.path === drag.path) {
|
||||
throw new Error('Quelle und Ziel sind identisch.');
|
||||
}
|
||||
if (drag.type === 'directory' && target.path.startsWith(`${drag.path.replace(/\/$/, '')}/`)) {
|
||||
if (drag.type === 'directory' && isPathInside(target.path, drag.path)) {
|
||||
throw new Error('Ein Ordner kann nicht in sich selbst verschoben werden.');
|
||||
}
|
||||
await createJob(event.altKey ? 'copy' : 'move', drag.path, destination, [drag.sourceWindowId, target.windowId]);
|
||||
@@ -1132,6 +1139,21 @@ function dirname(value) {
|
||||
return `/${parts.slice(0, -1).join('/')}`;
|
||||
}
|
||||
|
||||
function joinPath(parent, name) {
|
||||
return `${String(parent || '').replace(/\/+$/, '')}/${String(name || '').replace(/^\/+/, '')}`;
|
||||
}
|
||||
|
||||
function normalizePath(value) {
|
||||
const parts = String(value || '').split('/').filter(Boolean);
|
||||
return `/${parts.join('/')}`;
|
||||
}
|
||||
|
||||
function isPathInside(path, parent) {
|
||||
const normalizedPath = normalizePath(path);
|
||||
const normalizedParent = normalizePath(parent);
|
||||
return normalizedPath.startsWith(`${normalizedParent.replace(/\/$/, '')}/`);
|
||||
}
|
||||
|
||||
function formatBytes(bytes) {
|
||||
const value = Number(bytes || 0);
|
||||
if (value < 1024) return `${value} B`;
|
||||
|
||||
Reference in New Issue
Block a user