Bring back upload route to keep e2e happy
let's maybe remove it in next release
This commit is contained in:
27
src/apps.js
27
src/apps.js
@@ -93,6 +93,7 @@ exports = module.exports = {
|
||||
listEventlog,
|
||||
|
||||
downloadFile,
|
||||
uploadFile,
|
||||
|
||||
writeConfig,
|
||||
loadConfig,
|
||||
@@ -2887,6 +2888,32 @@ async function downloadFile(app, filePath) {
|
||||
return { stream: stdoutStream, filename, size };
|
||||
}
|
||||
|
||||
async function uploadFile(app, sourceFilePath, destFilePath) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof sourceFilePath, 'string');
|
||||
assert.strictEqual(typeof destFilePath, 'string');
|
||||
|
||||
// the built-in bash printf understands "%q" but not /usr/bin/printf.
|
||||
// ' gets replaced with '\'' . the first closes the quote and last one starts a new one
|
||||
const escapedDestFilePath = await shell.exec('uploadFile', `printf %q '${destFilePath.replace(/'/g, '\'\\\'\'')}'`, { shell: '/bin/bash' });
|
||||
debug(`uploadFile: ${sourceFilePath} -> ${escapedDestFilePath}`);
|
||||
|
||||
const execId = await createExec(app, { cmd: [ 'bash', '-c', `cat - > ${escapedDestFilePath}` ], tty: false });
|
||||
const destStream = await startExec(app, execId, { tty: false });
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const done = once(error => reject(new BoxError(BoxError.FS_ERROR, error.message)));
|
||||
|
||||
const sourceStream = fs.createReadStream(sourceFilePath);
|
||||
sourceStream.on('error', done);
|
||||
destStream.on('error', done);
|
||||
|
||||
destStream.on('finish', resolve);
|
||||
|
||||
sourceStream.pipe(destStream);
|
||||
});
|
||||
}
|
||||
|
||||
async function writeConfig(app) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user