From eaa3cc8b9629f256dda08faf7c7bd7ac35c49f38 Mon Sep 17 00:00:00 2001 From: Alex <alex.loo@protonmail.com> Date: Fri, 11 Jun 2021 03:04:39 +0200 Subject: [PATCH] fix: save on flash running mission --- Dockerfile | 1 + .../src/recorder/command-recorder.ts | 24 ++++--------------- .../src/view/briefingView.ts | 5 ++-- setup_trace.py | 7 +++--- start.sh | 6 +---- 5 files changed, 12 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index 13b0fd15..08f36bf1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,6 +21,7 @@ COPY .gitignore_recorder deadlock/.gitignore COPY setup_trace.py . RUN chmod 700 setup_trace.py RUN chown theia setup_trace.py + COPY start.sh . RUN chmod 504 deadlock/ -R RUN chmod 500 start.sh diff --git a/plugins/deadlock-extension/src/recorder/command-recorder.ts b/plugins/deadlock-extension/src/recorder/command-recorder.ts index 38cbe87a..ca941693 100644 --- a/plugins/deadlock-extension/src/recorder/command-recorder.ts +++ b/plugins/deadlock-extension/src/recorder/command-recorder.ts @@ -1,23 +1,8 @@ import GitMission from '../core/gitMission'; import { error, commitAndPushCode, CommitFrom, log } from './utils'; const async = require('async'); - -// regex to match command line in ps aux -/** - * group 0: Full match - * group 1: USER (theia) - * group 2: PID - * group 3: START - * group 4: TIME - * group 5: Command - */ - -const child = require('child_process'); const fs = require('fs'); -const regexPsCommand = - /(theia).+?([\d]+).+?([\d]+\:[\d]+).+?([\d+]\:[\d+]+) (.+)/; - class Command { public still: boolean; @@ -64,9 +49,11 @@ export default class CommandRecorder { let lastLineIndexWatched = 0; setInterval(() => { try { - const trace = fs.readFileSync('/tmp/.trace', 'utf8'); + const trace = fs.readFileSync('/home/theia/.bash_history', 'utf8'); const lines = trace.split(/\r?\n/); + this.commandsInProgress.forEach((command) => (command.still = false)); + for (let index = lastLineIndexWatched; index < lines.length; index++) { const line = lines[index]; if ( @@ -76,11 +63,10 @@ export default class CommandRecorder { line.indexOf('npm run') !== -1 || line.indexOf('npm start') !== -1 ) { - log('smth executed'); this.somethingExecuted(index, line); } } - lastLineIndexWatched = lines.length; + lastLineIndexWatched = lines.length - 1; // clear command down (means still = false) this.commandsInProgress.forEach((command) => { @@ -91,6 +77,6 @@ export default class CommandRecorder { } catch (e) { console.error(e); } - }, 500); + }, 1300); } } diff --git a/plugins/deadlock-extension/src/view/briefingView.ts b/plugins/deadlock-extension/src/view/briefingView.ts index 755c8901..589323eb 100644 --- a/plugins/deadlock-extension/src/view/briefingView.ts +++ b/plugins/deadlock-extension/src/view/briefingView.ts @@ -27,11 +27,10 @@ export default class BriefingView extends WebviewBase { } toBase64(file: string) { - const re = fs.readFileSync(path.join(DOCS_PATH, file), { + const result = fs.readFileSync(path.join(DOCS_PATH, file), { encoding: "base64", }); - console.log("re", re); - return re; + return result; } setupImages(text: string) { diff --git a/setup_trace.py b/setup_trace.py index 76286064..31358950 100644 --- a/setup_trace.py +++ b/setup_trace.py @@ -1,12 +1,11 @@ -open('/tmp/.trace', 'a').close() +open('/home/theia/.bash_history', 'a').close() bashrc = open('/home/theia/.bashrc', 'a') bashrc.write('\n') -bashrc.write('''PS4=\'$(echo $(date) $(history 1) >> /tmp/.trace)\'''') - +bashrc.write('HISTCONTROL=""') bashrc.write('\n') -bashrc.write('export PS4') +bashrc.write("PROMPT_COMMAND='history -a'") bashrc.write('\n') # Close the file diff --git a/start.sh b/start.sh index 46017bd7..4784e528 100755 --- a/start.sh +++ b/start.sh @@ -8,14 +8,10 @@ cp /tmp/.ssh/* ~/.ssh/ # start command recorder node deadlock/recorder.js & - -#trap 'if [[ "$BASH_COMMAND" == "java "* ]]; then printf "[%s]\n" ${BASH_COMMAND#echo}; false; fi' DEBUG -#set -T -#shopt -s extdebug - deluser theia sudo su theia --command "python setup_trace.py" +rm setup_trace.py # starting theia as THEIA su theia --command "node /home/theia/src-gen/backend/main.js /home/project --hostname=0.0.0.0 --plugins=local-dir:/home/plugins" \ No newline at end of file -- GitLab