From 7637307cbc177fac4c09e6fcdafeb3af7c6c81cd Mon Sep 17 00:00:00 2001 From: joshuaboud Date: Tue, 28 Jun 2022 14:40:27 -0300 Subject: [PATCH] give host to useSpawn --- navigator/src/components/FileNameEditor.vue | 8 ++++---- navigator/src/views/Browser.vue | 17 ++++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/navigator/src/components/FileNameEditor.vue b/navigator/src/components/FileNameEditor.vue index a063e43..593d4ef 100644 --- a/navigator/src/components/FileNameEditor.vue +++ b/navigator/src/components/FileNameEditor.vue @@ -60,15 +60,15 @@ export default { stderr.value = ""; try { if (!props.createNew) { - await (useSpawn(['mv', '-nT', props.entry.path, props.entry.path.split('/').slice(0, -1).concat(name.value).join('/')], { superuser: 'try' }).promise()); + await (useSpawn(['mv', '-nT', props.entry.path, props.entry.path.split('/').slice(0, -1).concat(name.value).join('/')], { superuser: 'try', host: props.entry.host }).promise()); } else if (['f', 'd'].includes(props.createNew)) { const parentPath = props.entry.resolvedType === 'd' ? props.entry.resolvedPath : props.entry.path.split('/').slice(0, -1).join('/'); const path = `${parentPath}/${name.value}` - await useSpawn(['test', '!', '(', '-e', path, '-o', '-L', path, ')'], { superuser: 'try' }).promise().catch(() => { throw new Error('File exists') }); + await useSpawn(['test', '!', '(', '-e', path, '-o', '-L', path, ')'], { superuser: 'try', host: props.entry.host }).promise().catch(() => { throw new Error('File exists') }); if (props.createNew === 'f') - await useSpawn(['touch', '-h', path], { superuser: 'try' }).promise(); + await useSpawn(['dd', 'count=0', 'oflag=nofollow', 'conv=excl,fsync', `of=${path}`], { superuser: 'try', host: props.entry.host }).promise(); else - await useSpawn(['mkdir', path], { superuser: 'try' }).promise(); + await useSpawn(['mkdir', path], { superuser: 'try', host: props.entry.host }).promise(); } emit('hide'); diff --git a/navigator/src/views/Browser.vue b/navigator/src/views/Browser.vue index 8225442..edd29b9 100644 --- a/navigator/src/views/Browser.vue +++ b/navigator/src/views/Browser.vue @@ -436,6 +436,7 @@ export default { return `cockpit-navigator-dowload_${now.getFullYear()}-${now.getMonth()+1}-${now.getDay()}_${now.getHours()}-${now.getMinutes()}-${now.getSeconds()}.zip`; } let items = [].concat(selection); // forces to be array + const host = pathHistory.current().host; if (items.length > 1) { const dirs = items.filter(item => item.type === 'd').map(item => item.path); if (dirs.length) { @@ -444,13 +445,13 @@ export default { items = items.filter(item => !containedRegex.test(item.path)); } const { common, relativePaths } = commonPath(items.map(item => item.path)); - streamProcDownload(['zip', '-rq', '-', ...relativePaths], getZipName(), { superuser: 'try', directory: common }); + streamProcDownload(['zip', '-rq', '-', ...relativePaths], getZipName(), { superuser: 'try', directory: common, host }); } else { let { path, name, host, resolvedType } = items[0]; if (resolvedType === 'd') { - streamProcDownload(['zip', '-rq', '-', '.'], `${name}.zip`, { superuser: 'try', directory: path }); + streamProcDownload(['zip', '-rq', '-', '.'], `${name}.zip`, { superuser: 'try', directory: path, host }); } else if (zip) { - streamProcDownload(['zip', '-q', '-', name], `${name}.zip`, { superuser: 'try', directory: path.split('/').slice(0, -1).join('/') || '/' }); + streamProcDownload(['zip', '-q', '-', name], `${name}.zip`, { superuser: 'try', directory: path.split('/').slice(0, -1).join('/') || '/', host }); } else { fileDownload(path, name, host); } @@ -464,7 +465,7 @@ export default { if (!await confirm.ask(`Permanently delete ${items.length} item${items.length > 1 ? 's' : ''}?`, items.map(i => i.path).join('\n'), true)) return; try { - await useSpawn(['rm', '-rf', '--', ...items.map(i => i.path)]).promise(); + await useSpawn(['rm', '-rf', '--', ...items.map(i => i.path)], { superuser: 'try', host: pathHistory.current().host}).promise(); } catch (state) { notifications.value.constructNotification("Failed to remove file(s)", errorStringHTML(state), 'error'); } @@ -517,10 +518,11 @@ export default { if (!result) return; // cancelled try { + const host = pathHistory.current().host; const parentPath = parentEntry.resolvedType === 'd' ? parentEntry.resolvedPath : parentEntry.path.split('/').slice(0, -1).join('/'); const path = `${parentPath}/${result.linkName}` - await useSpawn(['test', '!', '-e', path], { superuser: 'try' }).promise().catch(() => { throw new Error('File exists') }); - await useSpawn(['ln', '-snT', result.linkTarget, path], { superuser: 'try' }).promise(); + await useSpawn(['test', '!', '-e', path], { superuser: 'try', host }).promise().catch(() => { throw new Error('File exists') }); + await useSpawn(['ln', '-snT', result.linkTarget, path], { superuser: 'try', host }).promise(); } catch (state) { notifications.value.constructNotification("Failed to create link", errorStringHTML(state), 'error'); } @@ -531,7 +533,8 @@ export default { const { newTarget } = await modalPromptRef.value.prompt(`Edit link target for ${name}`) .addInput('newTarget', 'text', 'Link target', 'path/to/target', linkRawPath); try { - await useSpawn(['ln', '-snfT', newTarget, path], { superuser: 'try' }).promise(); + const host = pathHistory.current().host; + await useSpawn(['ln', '-snfT', newTarget, path], { superuser: 'try', host }).promise(); } catch (state) { notifications.value.constructNotification("Failed to edit link", errorStringHTML(state), 'error'); }