From: Vince Darley Date: Fri, 21 Feb 2003 16:05:41 +0000 (+0000) Subject: more documentation and better posix error handling X-Git-Tag: vfs-1-3~38 X-Git-Url: http://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=9e4586e2c21ea6691fbed1407e49791acb8b8c60;p=tclvfs more documentation and better posix error handling --- diff --git a/doc/vfs.n b/doc/vfs.n index 81f0322..810bdeb 100644 --- a/doc/vfs.n +++ b/doc/vfs.n @@ -168,7 +168,10 @@ Return TCL_OK or throw a posix error depending on whether the given access mode (which is an integer) is compatible with the file. .TP \fIcommand\fR \fIcreatedirectory\fR \fIr-r-a\fR -Create a directory with the given name. +Create a directory with the given name. The command can assume +that all sub-directories in the path exist and are valid, and +that the actual desired path does not yet exist (Tcl takes care +of all of that for us). .TP \fIcommand\fR \fIdeletefile\fR \fIr-r-a\fR Delete the given file. diff --git a/library/mk4vfs.tcl b/library/mk4vfs.tcl index 52092b7..b792cee 100644 --- a/library/mk4vfs.tcl +++ b/library/mk4vfs.tcl @@ -383,8 +383,7 @@ namespace eval mk4vfs { } else { set row [mk::select $view -count 1 parent $parent name $ele] if { $row == "" } { - return -code error "could not read \"$path\":\ - no such file or directory" + vfs::filesystem posixerror $::vfs::posix(ENOENT) } set v::cache($db,$parent,$ele) $row set parent $row @@ -426,8 +425,7 @@ namespace eval mk4vfs { if { $row != "" } { set v::cache($db,$parent,$tail) $row } else { - return -code error "could not read \"$path\":\ - no such file or directory" + vfs::filesystem posixerror $::vfs::posix(ENOENT) } } } @@ -512,13 +510,15 @@ namespace eval mk4vfs { set view $db.dirs set npath {} + # This actually does more work than is needed. Tcl's + # vfs only requires us to create the last piece, and + # Tcl already knows it is not a file. foreach ele $sp { set npath [file join $npath $ele] - if { ![catch {stat $db $npath sb}] } { + if {![catch {stat $db $npath sb}] } { if { $sb(type) != "directory" } { - return -code error "can't create directory \"$npath\":\ - file already exists" + vfs::filesystem posixerror $::vfs::posix(EROFS) } set parent [mk::cursor position sb(ino)] continue @@ -584,7 +584,7 @@ namespace eval mk4vfs { } } else { if {[llength $contents]} { - return -code error "Non-empty" + vfs::filesystem posixerror $::vfs::posix(ENOTEMPTY) } } array unset v::cache \ diff --git a/library/vfsUtils.tcl b/library/vfsUtils.tcl index f28ecb6..2325d51 100644 --- a/library/vfsUtils.tcl +++ b/library/vfsUtils.tcl @@ -361,7 +361,7 @@ set vfs::posix(ESRCH) 3 ;# No such process set vfs::posix(EINTR) 4 ;# Interrupted system call set vfs::posix(EIO) 5 ;# Input/output error set vfs::posix(ENXIO) 6 ;# Device not configured -set vfs::posix(E)2BIG 7 ;# Argument list too long +set vfs::posix(E2BIG) 7 ;# Argument list too long set vfs::posix(ENOEXEC) 8 ;# Exec format error set vfs::posix(EBADF) 9 ;# Bad file descriptor set vfs::posix(ECHILD) 10 ;# No child processes