~aleteoryx/tclircc

ref: c1e9562b7a4dc4f00d93c17ac50b8697b613582c tclircc/db/main.tcl -rw-r--r-- 990 bytes
c1e9562baleteoryx plugin loading prompts a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package require sqlite3
package require logger

set log [logger::init tclircc::db]

switch -- [set tcl_platform(platform)] {
  "windows" {
    set data_dir [file join [set env(APPDATA)] tclircc]
  }
  "unix" {
    if [info exists env(XDG_CONFIG_HOME)] {
      set data_dir [file join [set env(XDG_CONFIG_HOME)] tclircc]
    } elseif [info exists env(HOME)] {
      set data_dir [file join [set env(HOME)] .config tclircc]
    } else {
      return -code error {Missing $HOME or $XDG_CONFIG_HOME, can't store config!}
    }
  }
  default {
    return -code error {Unknown platform, can't store config.}
  }
}

file mkdir $data_dir

proc path_to_core {} {
  global data_dir
  return [file join $data_dir core.db]
}

proc backup {} {
  global log data_dir
  set backup_dir [string cat $data_dir _backup_ [clock microseconds]]
  ${log}::info "backing up data directory to $backup_dir..."
  file copy $data_dir $backup_dir
  ${log}::info "backup to $backup_dir complete!"
  return $backup_dir
}