• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stephendade / Rpanion-server / 15678546196

16 Jun 2025 10:38AM UTC coverage: 35.894% (+0.2%) from 35.71%
15678546196

Pull #288

github

web-flow
Merge 706cb0516 into c16840c55
Pull Request #288: Deb packaging

272 of 996 branches covered (27.31%)

Branch coverage included in aggregate %.

35 of 155 new or added lines in 12 files covered. (22.58%)

19 existing lines in 10 files now uncovered.

896 of 2258 relevant lines covered (39.68%)

2.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

34.78
/server/cloudUpload.js
1
const Rsync = require('rsync')
3✔
2
const path = require('path')
3✔
3
const fs = require('fs')
3✔
4
const os = require('os')
3✔
5
const { execSync } = require('child_process')
3✔
6

7
const logpaths = require('./paths.js')
3✔
8

9
class cloudUpload {
10
  constructor (settings) {
11
    this.options = {
9✔
12
      // the interval of sync, every 20 sec
13
      interval: 20
14
    }
15

16
    this.topfolder = logpaths.flightsLogsDir
9✔
17

18
    this.rsyncPid = null
9✔
19

20
    // load settings
21
    this.settings = settings
9✔
22
    this.options.doBinUpload = this.settings.value('cloud.doBinUpload', false)
9✔
23
    this.options.binUploadLink = this.settings.value('cloud.binUploadLink', '')
9✔
24
    this.options.syncDeletions = this.settings.value('cloud.syncDeletions', false)
9✔
25

26
    // create ssh key if none already
27
    if (fs.existsSync(os.homedir() + '/.ssh/')) {
9!
28
      const files = fs.readdirSync(os.homedir() + '/.ssh/')
×
29
      if (files.length === 0) {
×
30
        execSync('< /dev/zero ssh-keygen -q -N ""')
×
31
      }
32
    }
33

34
    // interval for upload checks
35
    this.intervalObj = setInterval(() => {
9✔
36
      console.log('Upload interval')
×
37
      if (this.options.doBinUpload) {
×
38
        console.log('Doing binfile')
×
39
        const rsync = new Rsync()
×
40
          .shell('ssh -o StrictHostKeyChecking=no')
41
          .flags('avzP')
42
          .source(this.topfolder + '/')
43
          .destination(this.options.binUploadLink)
44
          .include('*.bin')
45

46
        if (this.options.syncDeletions) {
×
47
          rsync.set('delete')
×
48
        }
49

50
        // Kill old rsync and create new one
51
        if (this.rsyncPid) {
×
52
          this.rsyncPid.kill()
×
53
        }
54

55
        this.rsyncPid = rsync.execute(function (error, code, cmd) {
×
56
          // we're done
57
          // this.rsyncPid = null
58
          if (error) {
×
59
            console.log(error)
×
60
            console.log(code)
×
61
            console.log(cmd)
×
62
          }
63
        })
64
      }
65
    }, this.options.interval * 1000)
66
  }
67

68
  quitting () {
69
    if (this.rsyncPid) {
×
70
      this.rsyncPid.kill()
×
71
    }
72
    clearInterval(this.intervalObj)
×
73
  }
74

75
  getSettings (callback) {
76
    // get current settings and pubkey(s)
77
    const pubkey = []
×
78
    if (fs.existsSync(os.homedir() + '/.ssh/')) {
×
79
      const files = fs.readdirSync(os.homedir() + '/.ssh/')
×
80
      files.forEach(file => {
×
81
        if (path.extname(file) === '.pub') {
×
82
          pubkey.push(fs.readFileSync(os.homedir() + '/.ssh/' + file, { encoding: 'utf8', flag: 'r' }))
×
83
        }
84
      })
85
    }
86
    // if pubKey is empty, create a new default ssh key
87
    if (pubkey.length === 0) {
×
NEW
88
      console.log('No SSH keys found, creating new one')
×
89
      execSync('< /dev/zero ssh-keygen -q -N ""')
×
90
      pubkey.push(fs.readFileSync(os.homedir() + '/.ssh/id_rsa.pub', { encoding: 'utf8', flag: 'r' }))
×
91
    }
92
    return callback(this.options.doBinUpload,
×
93
      this.options.binUploadLink, this.options.syncDeletions, pubkey)
94
  }
95

96
  setSettingsBin (doBinUpload, binUploadLink, syncDeletions) {
97
    // save new settings
98
    this.options.doBinUpload = doBinUpload
3✔
99
    this.options.binUploadLink = binUploadLink
3✔
100
    this.options.syncDeletions = syncDeletions
3✔
101

102
    // and save to file
103
    try {
3✔
104
      this.settings.setValue('cloud.doBinUpload', this.options.doBinUpload)
3✔
105
      this.settings.setValue('cloud.binUploadLink', this.options.binUploadLink)
3✔
106
      this.settings.setValue('cloud.syncDeletions', this.options.syncDeletions)
3✔
107
      console.log('Saved Cloud Bin settings')
3✔
108
    } catch (e) {
UNCOV
109
      console.log(e)
×
110
    }
111
  }
112

113
  // Get the rsync status for binlog
114
  conStatusBinStr () {
115
    if (!this.options.doBinUpload) {
6✔
116
      return 'Disabled'
3✔
117
    }
118
    if (this.rsyncPid) {
3!
119
      if (this.rsyncPid.exitCode === null) {
×
120
        return 'Running'
×
121
      } else if (this.rsyncPid.exitCode === 0) {
×
122
        return 'Success'
×
123
      } else {
124
        return 'Error running Rsync'
×
125
      }
126
    }
127
    return 'Waiting for first run'
3✔
128
  }
129
}
130

131
module.exports = cloudUpload
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc