BT.AutoUpdate.tcl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. #########################################################################
  2. ## BlackTools - The Ultimate Channel Control Script ##
  3. ## One TCL. One smart Eggdrop ##
  4. #########################################################################
  5. ######################### AutoUpdate TCL ############################
  6. #########################################################################
  7. ## ##
  8. ## BlackTools : http://blacktools.tclscripts.net ##
  9. ## Bugs report : http://www.tclscripts.net/ ##
  10. ## GitHub page : https://github.com/tclscripts/BlackToolS-TCL ##
  11. ## Online Help : irc://irc.undernet.org/tcl-help ##
  12. ## #TCL-HELP / UnderNet ##
  13. ## You can ask in english or romanian ##
  14. ## ##
  15. #########################################################################
  16. package require tls
  17. set black(backup_dir) "$black(dirname)/BT.backup"
  18. set black(log_file) "$black(dirname)/BT.update.log"
  19. set black(actdir) "scripts"
  20. ###
  21. proc blacktools:check_addons {hand chan} {
  22. global black
  23. if {[catch {package require http} no_http] != 0} {
  24. source $black(dirname)/BlackTools/Addons/http.tcl
  25. package require http
  26. }
  27. if {[catch {package require json} no_json] != 0} {
  28. source $black(dirname)/BlackTools/Addons/json.tcl
  29. package require json
  30. }
  31. if {[catch {package require github} no_github] != 0} {
  32. source $black(dirname)/BlackTools/Addons/github.tcl
  33. package require github
  34. }
  35. return 1
  36. }
  37. ###
  38. proc blacktools:update_check {nick hand host chan type} {
  39. global black
  40. set check_addons [blacktools:check_addons $hand $chan]
  41. set status [blacktools:update_verify]
  42. if {$status == -1} {
  43. blacktools:update_put $hand $chan 31 ""
  44. blacktools:tell $nick $host $hand $chan $chan autoupdate.31 ""
  45. return 0
  46. }
  47. set data [split $status "\n"]
  48. set new_version [lindex [lindex $data 0] 1]
  49. set last_modify [lindex [lindex $data 1] 2]
  50. set status [lindex [lindex $data 2] 1]
  51. if {$black(vers) != $new_version} {
  52. if {$type == 0} {
  53. blacktools:tell $nick $host $hand $chan $chan autoupdate.32 "$new_version"
  54. } else {
  55. return [list $new_version $last_modify]
  56. }
  57. } elseif {$last_modify != $black(current_modif)} {
  58. if {$type == 0} {
  59. blacktools:tell $nick $host $hand $chan $chan autoupdate.33 [ctime $last_modify]
  60. }
  61. return [list $new_version $last_modify]
  62. } else {
  63. if {$type == 0} {
  64. blacktools:tell $nick $host $hand $chan $chan autoupdate.5 ""
  65. }
  66. return 0
  67. }
  68. }
  69. ###
  70. proc blacktools:update:timer {} {
  71. global black
  72. if {$black(update_type) == 0} {
  73. if {![info exists black(update_disabled)]} {
  74. if {![info exists black(backup_update)]} {
  75. set update [catch {set status_update [blacktools:update "" "" ""]} error]
  76. if {$status_update != 0} {
  77. set found_version [lindex $status_update 0]
  78. set last_modif [lindex $status_update 1]
  79. if {$black(update_note) == 1} {
  80. blacktools:update:note 1 $last_modif $found_version
  81. }
  82. }
  83. } else {
  84. blacktools:update_put "" "" 40 ""
  85. }
  86. } else {
  87. blacktools:update_put "" "" 27 [list [ctime [unixtime]]]
  88. blacktools:update_put "" "" 30 [list $black(update_disabled)]
  89. }
  90. } else {
  91. if {$black(update_note) == 1} {
  92. if {![info exists black(update_disabled)]} {
  93. set check [blacktools:update_check "" "" "" "" 1]
  94. if {$check != 0} {
  95. set found_version [lindex $check 0]
  96. set last_modif [lindex $check 1]
  97. blacktools:update:note 0 $last_modif $found_version
  98. }
  99. }
  100. }
  101. }
  102. timer [time_return_minute $black(update_time_check)] blacktools:update:timer
  103. }
  104. ###
  105. proc blacktools:update:note {type num version} {
  106. global black botnick
  107. set time [unixtime]
  108. foreach user [userlist n] {
  109. set nonotes [getuser $user XTRA NO_NOTES]
  110. if {$nonotes == ""} {
  111. set check_note [blacktools:update_note_check $user $num]
  112. if {$check_note == 1} {continue}
  113. set getlang [string tolower [getuser $user XTRA OUTPUT_LANG]]
  114. if {$getlang == ""} { set getlang "[string tolower $black(default_lang)]" }
  115. set black(notes:announce:$user) 1
  116. set replace(%msg.1%) $version
  117. set replace(%msg.2%) [ctime $num]
  118. if {$type == 0} {
  119. set text [black:color:set $botnick $black(say.$getlang.autoupdate.43)]
  120. } else {
  121. set text [black:color:set $botnick $black(say.$getlang.autoupdate.44)]
  122. }
  123. set text [string map [array get replace] $text]
  124. notes:add $botnick "" $user "DB" "INBOX" $text "AUTOUPDATE:$num" 0
  125. }
  126. }
  127. }
  128. ###
  129. proc blacktools:update_note_check {hand num} {
  130. global black
  131. set found_it 0
  132. set file [open $black(notes_file) "r"]
  133. set timestamp [clock format [clock seconds] -format {%Y%m%d%H%M%S}]
  134. set temp "$black(tempdir)/notes_temp.$timestamp"
  135. set tempwrite [open $temp w]
  136. while {[gets $file line] != -1} {
  137. set handle [lindex [split $line] 4]
  138. if {[string equal -nocase $handle $hand]} {
  139. set sender [lindex [split $line] 6]
  140. set split_send [split $sender ":"]
  141. set last_update [lindex $split_send 1]
  142. set sender [lindex $split_send 0]
  143. if {[string equal -nocase $sender "AUTOUPDATE"] && [string equal -nocase $num $last_update]} {
  144. set found_it 1
  145. break
  146. }
  147. }
  148. }
  149. close $file
  150. return $found_it
  151. }
  152. ###
  153. proc blacktools:update {hand host chan} {
  154. global black
  155. if {[info exists black(backup_update)]} {
  156. blacktools:update_put $hand $chan 29 ""
  157. return 0
  158. }
  159. set error_b ""
  160. set file [open $black(log_file) w]
  161. close $file
  162. blacktools:update_put $hand $chan 27 [list [ctime [unixtime]]]
  163. blacktools:update_put $hand $chan 28 ""
  164. set check_addons [blacktools:check_addons $hand $chan]
  165. if {$check_addons == 0} {
  166. blacktools:update_put $hand $chan 1 ""
  167. return
  168. }
  169. set status [blacktools:update_verify]
  170. if {$status == -1} {
  171. blacktools:update_put $hand $chan 2 ""
  172. return 0
  173. }
  174. set data [split $status "\n"]
  175. set new_version [lindex [lindex $data 0] 1]
  176. set last_modify [lindex [lindex $data 1] 2]
  177. set status [lindex [lindex $data 2] 1]
  178. if {$black(vers) != $new_version} {
  179. blacktools:update_put $hand $chan 3 [list $new_version]
  180. } elseif {$last_modify != $black(current_modif)} {
  181. blacktools:update_put $hand $chan 4 [list $black(vers)]
  182. } else {
  183. blacktools:update_put $hand $chan 5 ""
  184. return 0
  185. }
  186. if {![file isdirectory $black(backup_dir)]} {
  187. if {[catch {file mkdir $black(backup_dir)} error] != 0} {
  188. blacktools:update_put $hand $chan 6 [list $error]
  189. return 0
  190. }
  191. }
  192. if {[file exists $black(backup_dir)/BlackTools.tcl]} {
  193. blacktools:update_put "" "" 7 ""
  194. file delete -force $black(backup_dir)/BlackTools
  195. file delete -force $black(backup_dir)/BlackTools.tcl
  196. }
  197. if {[catch {file copy -force "$black(dirname)/BlackTools" $black(backup_dir)} error_b] == 0} {
  198. blacktools:update_put "" "" 8 ""
  199. } else {
  200. blacktools:update_put $hand $chan 9 [list $error_b]
  201. file delete -force $black(backup_dir)
  202. return 0
  203. }
  204. if {[catch {file copy -force $black(tclconfig) $black(backup_dir)} error_b] != 0} {
  205. blacktools:update_put $hand $chan 10 ""
  206. file delete -force $black(backup_dir)
  207. return 0
  208. } else {
  209. blacktools:update_put "" "" 11 ""
  210. }
  211. set ::update_hand $hand
  212. set ::update_version $new_version
  213. set ::update_last_modify $last_modify
  214. set ::update_chan $chan
  215. blacktools:every 1000 {
  216. if {[file isdirectory "$black(backup_dir)/BlackTools"]} {
  217. set after_file_num [llength [glob-r "$black(backup_dir)/BlackTools"]]
  218. set current_file_num [llength [glob-r "$black(actdir)/BlackTools"]]
  219. if {$current_file_num == $after_file_num} {
  220. blacktools:update_backup
  221. break
  222. }
  223. }
  224. }
  225. return [list $new_version $last_modify]
  226. }
  227. ###
  228. proc blacktools:update_backup {} {
  229. global black
  230. set hand $::update_hand
  231. set new_version $::update_version
  232. set last_modify $::update_last_modify
  233. set chan $::update_chan
  234. set black(backup_update) 1
  235. set black(start_update) [unixtime]
  236. set black(update_file_saved) [llength [glob -nocomplain -directory "$black(dirname)/BlackTools/FILES" "*.txt"]]
  237. blacktools:update_put "" "" 12 ""
  238. blacktools:update_put "" "" 13 ""
  239. blacktools:update_put "" "" 14 ""
  240. blacktools:update_put $hand $chan 15 [list $new_version [ctime $last_modify]]
  241. blacktools:backup_run
  242. utimer 5 [list blacktools:update_start_download $hand $chan $new_version $last_modify]
  243. unset ::update_version
  244. unset ::update_last_modify
  245. unset ::update_hand
  246. unset ::update_chan
  247. }
  248. ###
  249. proc blacktools:backup_run {} {
  250. global black config
  251. set black(update_old_data) [blacktools:update_data 0 ""]
  252. set bt_file "$black(dirname)/BlackTools.tcl"
  253. set file [open $bt_file r]
  254. set data [read -nonewline $file]
  255. close $file
  256. set regexp_var2 "set black\\(dirname\\) \"(.*?)\""
  257. regexp -nocase $regexp_var2 $data found_line
  258. regexp -nocase $regexp_var2 $data -> found
  259. set found_line [string map [list $black(dirname) $black(backup_dir)] $found_line]
  260. regsub $regexp_var2 $data $found_line data
  261. blacktools:update_data 1 $data
  262. set file [open $config r]
  263. set data [read -nonewline $file]
  264. close $file
  265. set reg "source $black(dirname)/BlackTools.tcl"
  266. regsub $reg $data "source $black(dirname)/BlackTools.old.tcl" data
  267. set file [open $config w]
  268. puts $file $data
  269. close $file
  270. file rename -force "$black(dirname)/BlackTools.tcl" "$black(dirname)/BlackTools.old.tcl"
  271. }
  272. ###
  273. proc blacktools:update_start_download {hand chan new_version last_modify} {
  274. global black
  275. rehash
  276. set ::update_hand $hand
  277. set ::update_chan $chan
  278. file delete -force "$black(actdir)/BlackTools"
  279. ::github::github update tclscripts BlackTools-TCL $black(actdir)
  280. every 1000 {
  281. if {[file isdirectory $black(actdir)/BlackTools]} {
  282. blacktools:update_start_restore
  283. break
  284. }
  285. }
  286. }
  287. ###
  288. #https://wiki.tcl-lang.org/page/glob
  289. proc glob-r {{dir .}} {
  290. set res {}
  291. foreach i [lsort [glob -nocomplain -dir $dir *]] {
  292. if {[file type $i] eq {directory}} {
  293. eval lappend res [glob-r $i]
  294. } else {
  295. lappend res $i
  296. }
  297. }
  298. set res
  299. } ;# RS
  300. ###
  301. proc blacktools:update_unsetflag {} {
  302. global black
  303. if {[info exists black(backup_update)]} {
  304. unset black(backup_update)
  305. }
  306. }
  307. ###
  308. proc blacktools:update_start_restore {} {
  309. global black
  310. set hand $::update_hand
  311. set chan $::update_chan
  312. set userlang [blacktools:update_userlang $hand]
  313. if {![file isdirectory "$black(actdir)/BlackTools"]} {
  314. blacktools:update_put $hand $chan 16 ""
  315. file delete -force $black(backup_dir)
  316. blacktools:update_unsetflag
  317. return
  318. } elseif {![file exists "$black(actdir)/BlackTools.tcl"]} {
  319. blacktools:update_put $hand $chan 16 ""
  320. file delete -force $black(backup_dir)
  321. blacktools:update_unsetflag
  322. return
  323. }
  324. set end_download [unixtime]
  325. set dif [expr $end_download - $black(start_update)]
  326. blacktools:update_put "" "" 17 [list [return_time $userlang $dif]]
  327. set newdata [blacktools:update_data 0 ""]
  328. blacktools:update_put $hand $chan 18 ""
  329. set restore_config [blacktools:update_restore $black(update_old_data) $newdata]
  330. unset black(update_old_data)
  331. set newdata [lindex $restore_config 0]
  332. set num_var [lindex $restore_config 1]
  333. if {$num_var > 0} {
  334. set newdata [blacktools:update_data 1 $newdata]
  335. blacktools:update_put $hand $chan 19 [list $num_var]
  336. } else {
  337. blacktools:update_put "" "" 20 ""
  338. }
  339. blacktools:update_put $hand $chan 21 ""
  340. blacktools:update_restore_files
  341. set ::update_hand $::update_hand
  342. set ::update_chan $::update_chan
  343. every 1000 {
  344. set info_files_num [llength [glob -nocomplain -directory "$black(actdir)/BlackTools/FILES" "*.txt"]]
  345. if {$info_files_num == $black(update_file_saved)} {
  346. blacktools:update_end $info_files_num
  347. break
  348. }
  349. }
  350. }
  351. ###
  352. proc blacktools:update_end {num} {
  353. global black config
  354. set hand $::update_hand
  355. set chan $::update_chan
  356. set userlang [blacktools:update_userlang $hand]
  357. set end_update [unixtime]
  358. set dif [expr $end_update - $black(start_update)]
  359. unset black(start_update)
  360. if {$num == 0} {
  361. blacktools:update_put "" "" 22 ""
  362. } else {
  363. blacktools:update_put $hand $chan 23 [list $num]
  364. }
  365. set file [open $config r]
  366. set data [read -nonewline $file]
  367. close $file
  368. set reg "source $black(actdir)/BlackTools.old.tcl"
  369. regsub $reg $data "source $black(actdir)/BlackTools.tcl" data
  370. set file [open $config w]
  371. puts $file $data
  372. close $file
  373. rehash
  374. if {[info exists ::update_hand]} {
  375. unset ::update_hand
  376. }
  377. if {[info exists ::update_chan]} {
  378. unset ::update_chan
  379. }
  380. blacktools:update_unsetflag
  381. blacktools:update_put $hand $chan 24 [list [return_time $userlang $dif]]
  382. blacktools:update_put $hand $chan 25 [list $black(backup_dir) $black(log_file)]
  383. blacktools:update_put $hand $chan 26 ""
  384. unset black(update_file_saved)
  385. file delete -force "$black(actdir)/BlackTools.old.tcl"
  386. }
  387. ###
  388. proc blacktools:update_restore_files {} {
  389. global black
  390. set files ""
  391. set files [glob -nocomplain -directory "$black(backup_dir)/BlackTools/FILES" "*.txt"]
  392. if {![file isdirectory "$black(actdir)/BlackTools/FILES"]} {
  393. file mkdir "$black(actdir)/BlackTools/FILES"
  394. }
  395. set counter 0
  396. foreach f $files {
  397. incr counter
  398. set filename [file tail $f]
  399. file copy -force $f "$black(actdir)/BlackTools/FILES/$filename"
  400. }
  401. return $counter
  402. }
  403. ###
  404. proc blacktools:update_set_time {num type} {
  405. global black
  406. set bt_file "$black(dirname)/BlackTools.tcl"
  407. set file [open $bt_file r]
  408. set data [read -nonewline $file]
  409. close $file
  410. set regexp_var2 "set black\\(update_time_check\\) \"(.*?)\""
  411. regexp -nocase $regexp_var2 $data -> found
  412. if {$type == 0} {
  413. return $found
  414. } else {
  415. regexp -nocase $regexp_var2 $data found_line
  416. set found_line [string map [list $found $num] $found_line]
  417. regsub $regexp_var2 $data $found_line data
  418. blacktools:update_data 1 $data
  419. }
  420. }
  421. ###
  422. proc blacktools:update_on_off {type} {
  423. global black
  424. set regexp_var2 "set black\\(update_type\\) \"(.*?)\""
  425. set bt_file "$black(dirname)/BlackTools.tcl"
  426. set file [open $bt_file r]
  427. set data [read -nonewline $file]
  428. close $file
  429. regexp -nocase $regexp_var2 $data found_line
  430. regexp -nocase $regexp_var2 $data -> found
  431. if {$type == 0 && $found == 0} {
  432. return 0
  433. }
  434. if {$type == 1 && $found == 1} {
  435. return 1
  436. }
  437. switch $type {
  438. 0 {
  439. set found_line [string map {"1" "0"} $found_line]
  440. regsub $regexp_var2 $data $found_line data
  441. blacktools:update_data 1 $data
  442. return 2
  443. }
  444. 1 {
  445. set found_line [string map {"0" "1"} $found_line]
  446. regsub $regexp_var2 $data $found_line data
  447. blacktools:update_data 1 $data
  448. return 3
  449. }
  450. }
  451. }
  452. ###
  453. proc blacktools:update_restore {data newdata} {
  454. global black
  455. set current_data $newdata
  456. set variables [regexp -all -inline {set black\((.+?)\)} $data]
  457. regsub -all {set black\((.+?)\)} $variables "" variables
  458. set var_nomodif "name author vers site current_modif"
  459. set var_counter 0
  460. foreach var $variables {
  461. if {$var == ""} {continue}
  462. if {[lsearch -nocase $var_nomodif $var] > -1} {continue}
  463. set regexp_var "set black\\($var\\) \\{(.*?)\\}"
  464. set regexp_var2 "set black\\($var\\) \"(.*?)\""
  465. regexp -nocase $regexp_var $data found_old
  466. regexp -nocase $regexp_var2 $data found_old_2
  467. if {[info exists found_old]} {
  468. set found_old [concat $found_old]
  469. regexp -nocase $regexp_var $newdata found_new
  470. if {[info exists found_new]} {
  471. if {[string equal -nocase $found_old $found_new]} {continue}
  472. incr var_counter
  473. regsub $regexp_var $current_data $found_old current_data
  474. unset found_new
  475. }
  476. unset found_old
  477. }
  478. }
  479. foreach var $variables {
  480. if {$var == ""} {continue}
  481. if {[lsearch -nocase $var_nomodif $var] > -1} {continue}
  482. set regexp_var2 "set black\\($var\\) \"(.*?)\""
  483. regexp -nocase $regexp_var2 $data found_old_2
  484. if {[info exists found_old_2]} {
  485. set found_old_2 [concat $found_old_2]
  486. regexp -nocase $regexp_var2 $newdata found_new_2
  487. if {[info exists found_new_2]} {
  488. if {[string equal -nocase $found_old_2 $found_new_2]} {continue}
  489. incr var_counter
  490. regsub $regexp_var2 $current_data $found_old_2 current_data
  491. unset found_new_2
  492. }
  493. unset found_old_2
  494. }
  495. }
  496. return [list $current_data $var_counter]
  497. }
  498. ###
  499. proc blacktools:update_data {type data} {
  500. global black
  501. set bt_file "$black(dirname)/BlackTools.tcl"
  502. if {![file exists $bt_file]} {
  503. return 0
  504. }
  505. if {$type == 0} {
  506. set file [open $bt_file r]
  507. set data [read -nonewline $file]
  508. close $file
  509. return $data
  510. } else {
  511. set file [open $bt_file w]
  512. puts $file $data
  513. close $file
  514. }
  515. }
  516. ###
  517. proc blacktools:update_verify {} {
  518. global black
  519. set link "https://raw.githubusercontent.com/tclscripts/BlackTools-TCL/master/VERSION"
  520. set ipq [http::config -useragent "lynx"]
  521. set error [catch {set ipq [::http::geturl $link -timeout 10000]} eror]
  522. set status [::http::status $ipq]
  523. if {$status != "ok"} {
  524. ::http::cleanup $ipq
  525. return -1
  526. }
  527. set getipq [::http::data $ipq]
  528. ::http::cleanup $ipq
  529. return $getipq
  530. }
  531. ###
  532. proc blacktools:update_userlang {nick} {
  533. global black
  534. if {$nick == ""} {return [string tolower $black(default_lang)]}
  535. set hand [nick2hand $nick]
  536. set userlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  537. if {$userlang == ""} { set userlang "[string tolower $black(default_lang)]" }
  538. return $userlang
  539. }
  540. ###
  541. proc blacktools:update_put {nick chan num var} {
  542. global black
  543. set counter 0
  544. foreach v $var {
  545. incr counter
  546. set replace(%msg.${counter}%) $v
  547. }
  548. if {$nick != "" && $chan != ""} {
  549. set hand [nick2hand $nick]
  550. set getmethod [getuser $hand XTRA OUTPUT_TYPE]
  551. set userlang [string tolower [getuser $hand XTRA OUTPUT_LANG]]
  552. if {$userlang == ""} { set userlang "[string tolower $black(default_lang)]" }
  553. if {$getmethod == ""} { set getmethod "0" }
  554. set text [black:color:set "" $black(say.${userlang}.autoupdate.${num})]
  555. set reply [join $text]
  556. set reply [string map [array get replace] $reply]
  557. switch $getmethod {
  558. 0 {
  559. putserv "NOTICE $nick :$reply"
  560. }
  561. 1 {
  562. putserv "PRIVMSG $chan :$reply"
  563. }
  564. 2 {
  565. putserv "PRIVMSG $nick :$reply"
  566. }
  567. }
  568. } else {
  569. set lang [string tolower $black(default_lang)]
  570. set text [black:color:set "" $black(say.${lang}.autoupdate.${num})]
  571. set reply [join $text]
  572. set reply [string map [array get replace] $reply]
  573. }
  574. putlog "\[BT\] $reply"
  575. set file [open $black(log_file) a]
  576. puts $file $reply
  577. close $file
  578. }
  579. ###
  580. #https://wiki.tcl-lang.org/page/every
  581. proc blacktools:every {interval script} {
  582. global everyIds
  583. if {$interval eq {cancel}} {
  584. after cancel $everyIds($script)
  585. return
  586. }
  587. set everyIds($script) [after $interval [namespace code [info level 0]]]
  588. set rc [catch {uplevel #0 $script} result]
  589. if {$rc == [catch break]} {
  590. after cancel $everyIds($script)
  591. set rc 0
  592. } elseif {$rc == [catch continue]} {
  593. # Ignore - just consume the return code
  594. set rc 0
  595. }
  596. # TODO: Need better handling of errorInfo etc...
  597. return -code $rc $result
  598. }