Overview
Comment: | Merged in updates from trunk |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | internal_sha1 |
Files: | files | file ages | folders |
SHA1: |
ee9eb7ed98663bc2e73768874fd038e4 |
User & Date: | rkeene on 2014-11-06 00:37:20.285 |
Other Links: | branch diff | manifest | tags |
Context
2014-11-06
| ||
02:29 | Updated to use C-based implementation of SHA1 Closed-Leaf check-in: 853a9068a7 user: rkeene tags: internal_sha1 | |
00:37 | Merged in updates from trunk check-in: ee9eb7ed98 user: rkeene tags: internal_sha1 | |
2014-11-05
| ||
21:41 | Fixed cleanup issue which was causing excessive lookups check-in: cc5a68a6de user: rkeene tags: trunk | |
2014-11-03
| ||
23:16 | Started work on an internal sha1 implementation check-in: 5ebe069cbf user: rkeene tags: internal_sha1 | |
Changes
Modified Makefile
from [fe29eeac49]
to [bee1193267].
︙ | ︙ | |||
26 27 28 29 30 31 32 | appfsd: appfsd.o $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o appfsd appfsd.o $(LIBS) appfsd.o: appfsd.c appfsd.tcl.h $(CC) $(CPPFLAGS) $(CFLAGS) -o appfsd.o -c appfsd.c | | | | 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | appfsd: appfsd.o $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o appfsd appfsd.o $(LIBS) appfsd.o: appfsd.c appfsd.tcl.h $(CC) $(CPPFLAGS) $(CFLAGS) -o appfsd.o -c appfsd.c appfsd.tcl.h: appfsd.tcl sha1.tcl sed '/@@SHA1\.TCL@@/ r sha1.tcl' appfsd.tcl | sed '/@@SHA1\.TCL@@/ d' | sed 's@[\\"]@\\&@g;s@^@ "@;s@$$@\\n"@' > appfsd.tcl.h.new mv appfsd.tcl.h.new appfsd.tcl.h install: appfsd if [ ! -d '$(DESTDIR)$(sbindir)' ]; then mkdir -p '$(DESTDIR)$(sbindir)'; chmod 755 '$(DESTDIR)$(sbindir)'; fi cp appfsd '$(DESTDIR)$(sbindir)/' clean: |
︙ | ︙ |
Modified appfsd.c
from [e3ba0e89d2]
to [72840611b5].
︙ | ︙ | |||
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | const char *fmt; }; static Tcl_Interp *appfs_create_TclInterp(const char *cachedir) { Tcl_Interp *interp; int tcl_ret; interp = Tcl_CreateInterp(); if (interp == NULL) { fprintf(stderr, "Unable to create Tcl Interpreter. Aborting.\n"); return(NULL); } tcl_ret = Tcl_Init(interp); if (tcl_ret != TCL_OK) { fprintf(stderr, "Unable to initialize Tcl. Aborting.\n"); return(NULL); } tcl_ret = Tcl_Eval(interp, "" #include "appfsd.tcl.h" ""); if (tcl_ret != TCL_OK) { fprintf(stderr, "Unable to initialize Tcl AppFS script. Aborting.\n"); fprintf(stderr, "Tcl Error is: %s\n", Tcl_GetStringResult(interp)); return(NULL); } if (Tcl_SetVar(interp, "::appfs::cachedir", cachedir, TCL_GLOBAL_ONLY) == NULL) { fprintf(stderr, "Unable to set cache directory. This should never fail.\n"); return(NULL); } tcl_ret = Tcl_Eval(interp, "::appfs::init"); if (tcl_ret != TCL_OK) { fprintf(stderr, "Unable to initialize Tcl AppFS script (::appfs::init). Aborting.\n"); fprintf(stderr, "Tcl Error is: %s\n", Tcl_GetStringResult(interp)); return(NULL); } return(interp); } static int appfs_Tcl_Eval(Tcl_Interp *interp, int objc, const char *cmd, ...) { Tcl_Obj **objv; const char *arg; va_list argp; | > > > > > > > > > > > > > > > > | 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | const char *fmt; }; static Tcl_Interp *appfs_create_TclInterp(const char *cachedir) { Tcl_Interp *interp; int tcl_ret; APPFS_DEBUG("Creating new Tcl interpreter for TID = 0x%llx", (unsigned long long) pthread_self()); interp = Tcl_CreateInterp(); if (interp == NULL) { fprintf(stderr, "Unable to create Tcl Interpreter. Aborting.\n"); return(NULL); } tcl_ret = Tcl_Init(interp); if (tcl_ret != TCL_OK) { fprintf(stderr, "Unable to initialize Tcl. Aborting.\n"); Tcl_DeleteInterp(interp); return(NULL); } tcl_ret = Tcl_Eval(interp, "" #include "appfsd.tcl.h" ""); if (tcl_ret != TCL_OK) { fprintf(stderr, "Unable to initialize Tcl AppFS script. Aborting.\n"); fprintf(stderr, "Tcl Error is: %s\n", Tcl_GetStringResult(interp)); Tcl_DeleteInterp(interp); return(NULL); } if (Tcl_SetVar(interp, "::appfs::cachedir", cachedir, TCL_GLOBAL_ONLY) == NULL) { fprintf(stderr, "Unable to set cache directory. This should never fail.\n"); Tcl_DeleteInterp(interp); return(NULL); } tcl_ret = Tcl_Eval(interp, "::appfs::init"); if (tcl_ret != TCL_OK) { fprintf(stderr, "Unable to initialize Tcl AppFS script (::appfs::init). Aborting.\n"); fprintf(stderr, "Tcl Error is: %s\n", Tcl_GetStringResult(interp)); Tcl_DeleteInterp(interp); return(NULL); } Tcl_HideCommand(interp, "glob", "glob"); Tcl_HideCommand(interp, "exec", "exec"); Tcl_HideCommand(interp, "pid", "pid"); Tcl_HideCommand(interp, "auto_load_index", "auto_load_index"); Tcl_HideCommand(interp, "unknown", "unknown"); return(interp); } static int appfs_Tcl_Eval(Tcl_Interp *interp, int objc, const char *cmd, ...) { Tcl_Obj **objv; const char *arg; va_list argp; |
︙ | ︙ |
Modified appfsd.tcl
from [a0bff81028]
to [86cb2b92c8].
1 2 3 4 | #! /usr/bin/env tclsh package require http 2.7 package require sqlite3 | > > | > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #! /usr/bin/env tclsh package require http 2.7 package require sqlite3 if {[catch { package require sha1 }]} { @@SHA1.TCL@@ package require sha1 } namespace eval ::appfs { variable cachedir "/tmp/appfs-cache" variable ttl 3600 variable nttl 60 proc _hash_sep {hash {seps 4}} { |
︙ | ︙ | |||
24 25 26 27 28 29 30 | set filekey [_hash_sep $filekey] } set file [file join $::appfs::cachedir $filekey] file mkdir [file dirname $file] | | > > > | | | | | | | | | | | | | | | | | | | | | | < | 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | set filekey [_hash_sep $filekey] } set file [file join $::appfs::cachedir $filekey] file mkdir [file dirname $file] if {[file exists $file]} { return $file } set tmpfile "${file}.[expr {rand()}]" set fd [open $tmpfile "w"] fconfigure $fd -translation binary catch { set token [::http::geturl $url -channel $fd -binary true] } if {[info exists token]} { set ncode [::http::ncode $token] ::http::reset $token } else { set ncode "900" } close $fd if {$keyIsHash} { set hash [string tolower [sha1::sha1 -hex -file $tmpfile]] } else { set hash $key } if {$ncode == "200" && $hash == $key} { file rename -force -- $tmpfile $file } else { file delete -force -- $tmpfile } return $file } proc _isHash {value} { |
︙ | ︙ | |||
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | switch -- $os { "linux" - "freebsd" - "openbsd" - "netbsd" { return $os } "sunos" { return "solaris" } } return -code error "Unable to normalize OS: $os" } proc _normalizeCPU {cpu} { set cpu [string tolower [string trim $cpu]] switch -glob -- $cpu { "i?86" { return "ix86" } "x86_64" { return $cpu } } return -code error "Unable to normalize CPU: $cpu" } proc init {} { | > > > > > > | 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | switch -- $os { "linux" - "freebsd" - "openbsd" - "netbsd" { return $os } "sunos" { return "solaris" } "noarch" - "none" - "any" - "all" { return "noarch" } } return -code error "Unable to normalize OS: $os" } proc _normalizeCPU {cpu} { set cpu [string tolower [string trim $cpu]] switch -glob -- $cpu { "i?86" { return "ix86" } "x86_64" { return $cpu } "noarch" - "none" - "any" - "all" { return "noarch" } } return -code error "Unable to normalize CPU: $cpu" } proc init {} { |
︙ | ︙ | |||
137 138 139 140 141 142 143 | } proc download {hostname hash {method sha1}} { set url "http://$hostname/appfs/$method/$hash" set file [_cachefile $url $hash] if {![file exists $file]} { | | | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | } proc download {hostname hash {method sha1}} { set url "http://$hostname/appfs/$method/$hash" set file [_cachefile $url $hash] if {![file exists $file]} { return -code error "Unable to fetch (file does not exist: $file)" } return $file } proc getindex {hostname} { set now [clock seconds] |
︙ | ︙ | |||
171 172 173 174 175 176 177 | catch { set token [::http::geturl $url] if {[::http::ncode $token] == "200"} { set indexhash_data [::http::data $token] } ::http::reset $token | | | 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | catch { set token [::http::geturl $url] if {[::http::ncode $token] == "200"} { set indexhash_data [::http::data $token] } ::http::reset $token ::http::cleanup $token } if {![info exists indexhash_data]} { # Cache this result for 60 seconds _db eval {INSERT OR REPLACE INTO sites (hostname, lastUpdate, ttl) VALUES ($hostname, $now, $::appfs::nttl);} return -code error "Unable to fetch $url" |
︙ | ︙ | |||
207 208 209 210 211 212 213 | if {$line == ""} { continue } set work [split $line ","] unset -nocomplain pkgInfo | > | | | | | | | > > > | 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | if {$line == ""} { continue } set work [split $line ","] unset -nocomplain pkgInfo if {[catch { set pkgInfo(package) [lindex $work 0] set pkgInfo(version) [lindex $work 1] set pkgInfo(os) [_normalizeOS [lindex $work 2]] set pkgInfo(cpuArch) [_normalizeCPU [lindex $work 3]] set pkgInfo(hash) [string tolower [lindex $work 4]] set pkgInfo(hash_type) "sha1" set pkgInfo(isLatest) [expr {!![lindex $work 5]}] }]} { continue } if {![_isHash $pkgInfo(hash)]} { continue } lappend curr_packages $pkgInfo(hash) |
︙ | ︙ |
Added sha1.tcl version [a8b3b2afbe].