Skip to content

Commit

Permalink
Provide operation when tcl files unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
chpock committed May 17, 2024
1 parent b10bda3 commit 254f6b4
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 75 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2024-05-18 Konstantin Kushnir <[email protected]>
* Provide successful operation when tcl files unavailable. CookFS should
work when readerchannel.tcl memchan.tcl pages.tcl fsindex.tcl unavailable,
but C module contains all required functionality.

2024-05-17 Konstantin Kushnir <[email protected]>
* Add support for c-writerchannel. This removes the dependency on vfs::memchan and improves memory utilization/performance

Expand Down
82 changes: 47 additions & 35 deletions scripts/cookvfs.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ proc cookfs::sha1 {args} {

proc cookfs::pages {args} {
if {[pkgconfig get c-pages]} {
if {![llength [info commands ::cookfs::c::pages]]} {
package require vfs::cookfs::c::pages [pkgconfig get package-version]
}
return [uplevel #0 [concat [list ::cookfs::c::pages] $args]]
} else {
if {![llength [info commands ::cookfs::tcl::pages]]} {
Expand All @@ -54,9 +51,6 @@ proc cookfs::pages {args} {

proc cookfs::fsindex {args} {
if {[pkgconfig get c-fsindex]} {
if {![llength [info commands ::cookfs::c::fsindex]]} {
package require vfs::cookfs::c::fsindex [pkgconfig get package-version]
}
return [uplevel #0 [concat [list ::cookfs::c::fsindex] $args]]
} else {
if {![llength [info commands ::cookfs::tcl::fsindex]]} {
Expand All @@ -75,35 +69,39 @@ proc cookfs::initialize {} {
variable pkginitialized

if {![info exists pkginitialized]} {
package require vfs::cookfs::pkgconfig

# load Tcl versions of packages for now
package require vfs::cookfs::tcl::vfs [pkgconfig get package-version]
package require vfs::cookfs::tcl::memchan [pkgconfig get package-version]
package require vfs::cookfs::tcl::writer [pkgconfig get package-version]
package require vfs::cookfs::tcl::optimize [pkgconfig get package-version]

# load C version of Pages if available
if {[pkgconfig get c-pages]} {
package require vfs::cookfs::c [pkgconfig get package-version]
} {
package require vfs::cookfs::tcl::pages [pkgconfig get package-version]
}

# load C version of Fsindex if available
if {[pkgconfig get c-fsindex]} {
package require vfs::cookfs::c [pkgconfig get package-version]
} {
package require vfs::cookfs::tcl::fsindex [pkgconfig get package-version]
}

package require vfs::cookfs::tcl::readerchannel [pkgconfig get package-version]
# load C version of Readerchannel if available
if {[pkgconfig get c-readerchannel]} {
package require vfs::cookfs::c [pkgconfig get package-version]
}

set pkginitialized 1
catch { package require vfs::cookfs::c }

# load Tcl version of pkgconfig if we don't have such a command in C module
if { ![llength [info commands cookfs::pkgconfig]] } {
package require vfs::cookfs::pkgconfig
}

# load Tcl versions of packages for now
package require vfs::cookfs::tcl::vfs [pkgconfig get package-version]
package require vfs::cookfs::tcl::writer [pkgconfig get package-version]
package require vfs::cookfs::tcl::optimize [pkgconfig get package-version]

# load C version of Pages if available
if {![pkgconfig get c-pages]} {
package require vfs::cookfs::tcl::pages [pkgconfig get package-version]
}

# load C version of Fsindex if available
if {![pkgconfig get c-fsindex]} {
package require vfs::cookfs::tcl::fsindex [pkgconfig get package-version]
}

# load C version of Readerchannel if available
if {![pkgconfig get c-readerchannel]} {
package require vfs::cookfs::tcl::readerchannel [pkgconfig get package-version]
}

# load C version of Writerchannel if available
if {![pkgconfig get c-writerchannel]} {
package require vfs::cookfs::tcl::memchan [pkgconfig get package-version]
}

set pkginitialized 1
}

# decide on crc32 implementation based on if zlib command is present
Expand Down Expand Up @@ -247,6 +245,20 @@ proc cookfs::Mount {args} {
set fs(tclreaderchannel) [expr {$fs(tclpages) || ![pkgconfig get c-readerchannel] || $opt(tcl-readerchannel)}]
set fs(tclwriterchannel) [expr {$fs(tclpages) || $fs(tclfsindex) || ![pkgconfig get c-writerchannel] || $opt(tcl-writerchannel)}]

# load Tcl packages if we need them but don't currently have them
if {$fs(tclpages) && [catch {package present vfs::cookfs::tcl::pages}]} {
package require vfs::cookfs::tcl::pages [pkgconfig get package-version]
}
if {$fs(tclfsindex) && [catch {package present vfs::cookfs::tcl::fsindex}]} {
package require vfs::cookfs::tcl::fsindex [pkgconfig get package-version]
}
if {$fs(tclreaderchannel) && [catch {package present vfs::cookfs::tcl::readerchannel}]} {
package require require vfs::cookfs::tcl::readerchannel [pkgconfig get package-version]
}
if {$fs(tclwriterchannel) && [catch {package present vfs::cookfs::tcl::memchan}]} {
package require require vfs::cookfs::tcl::memchan [pkgconfig get package-version]
}

# initialize pages
if {$opt(pagesobject) == ""} {
set pagesoptions [list -cachesize $opt(pagecachesize) \
Expand Down
34 changes: 2 additions & 32 deletions scripts/readerchannel.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,16 @@
#
# (c) 2010 Wojciech Kocjan, Pawel Salawa
# (c) 2011-2014 Wojciech Kocjan
# (c) 2024 Konstantin Kushnir

namespace eval cookfs {}

# creates a new channel for reading data from a VFS
# uses reflected channels
proc cookfs::createReadableChannel {fsid path} {
proc cookfs::createReadableChannel {fsid chunklist} {
variable dirlistParameters
upvar #0 $fsid fs

# try to get information about specified path
if {[catch {
set fileinfo [$fs(index) get $path]
}]} {
return ""
}

# return if trying to open a directory
if {([llength $fileinfo] != 3)} {
return ""
}

foreach {mtime size chunklist} $fileinfo break

# if this is a small file, currently pending write, pass it to memchan
if {([llength $chunklist] == 3) && ([lindex $chunklist 0] < 0)} {
#vfs::log [list cookfs::createReadableChannel $fsid $path smallfile]
if {!$fs(tclwriterchannel) && [pkgconfig get c-writerchannel]} {
return [::cookfs::c::writerchannel $fs(pages) $fs(index) $fs(writer) $path true]
} else {
return [lindex [initMemchan $fsid $path true] 0]
}
}

# create C channel if available and was not disabled
if {!$fs(tclreaderchannel) && [pkgconfig get c-readerchannel]} {
set chan [cookfs::c::readerchannel $fs(pages) $fs(index) $chunklist]
fconfigure $chan -buffersize 65536
return $chan
}

set id [incr fs(channelId)]
set chid "$fsid.ch$id"
upvar #0 $chid ch
Expand Down
25 changes: 17 additions & 8 deletions scripts/vfs.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,26 @@ proc cookfs::vfshandleOpen {fsid relative mode} {
"" - r {
#vfs::log [list cookfs::vfshandleOpen $fsid $relative read]
if {[catch {
set channel [cookfs::createReadableChannel $fsid $relative]
} error]} {
#vfs::log [list cookfs::vfshandleOpen $fsid $relative error $::errorInfo]
$fs(index) get $relative
} fileinfo]} {
vfs::filesystem posixerror $::cookfs::posix(ENOENT)
}

if {$channel == ""} {
#vfs::log [list cookfs::vfshandleOpen $fsid $relative {does not exist}]
vfs::filesystem posixerror $::cookfs::posix(ENOENT)
if {[llength $fileinfo] != 3} {
vfs::filesystem posixerror $::cookfs::posix(EISDIR)
}
foreach {mtime size chunklist} $fileinfo break
# if this is a small file, currently pending write, pass it to memchan
if {([llength $chunklist] == 3) && ([lindex $chunklist 0] < 0)} {
if {!$fs(tclwriterchannel) && [pkgconfig get c-writerchannel]} {
set channel [::cookfs::c::writerchannel $fs(pages) $fs(index) $fs(writer) $relative true]
} else {
set channel [lindex [initMemchan $fsid $relative true] 0]
}
} elseif {!$fs(tclreaderchannel) && [pkgconfig get c-readerchannel]} {
set channel [cookfs::c::readerchannel $fs(pages) $fs(index) $chunklist]
} else {
set channel [cookfs::createReadableChannel $fsid $chunklist]
}

return [list $channel ""]
}
r+ {
Expand Down

0 comments on commit 254f6b4

Please sign in to comment.