From: Vince Darley Date: Tue, 18 Feb 2003 21:41:50 +0000 (+0000) Subject: cleanup of posix error handling X-Git-Tag: vfs-1-3~48 X-Git-Url: https://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=b7314473be74f43a39a3ec265a2d4e10869c20e2;p=tclvfs cleanup of posix error handling --- diff --git a/generic/vfs.c b/generic/vfs.c index 3d8d2be..43e0ca5 100644 --- a/generic/vfs.c +++ b/generic/vfs.c @@ -13,7 +13,7 @@ * one interpreter will be used to add/remove mounts and volumes, * it does cope with multiple interpreters in multiple threads. * - * Copyright (c) 2001 Vince Darley. + * Copyright (c) 2001-2003 Vince Darley. * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -31,7 +31,7 @@ #ifdef BUILD_vfs #undef TCL_STORAGE_CLASS #define TCL_STORAGE_CLASS DLLEXPORT -#endif /* BUILD_Vfs */ +#endif /* BUILD_vfs */ /* * Only the _Init function is exported. @@ -707,7 +707,7 @@ VfsFilesystemObjCmd(dummy, interp, objc, objv) return TCL_ERROR; } Tcl_SetErrno(posixError); - return TCL_OK; + return -1; } case VFS_NORMALIZE: { Tcl_Obj *path; @@ -1271,16 +1271,13 @@ VfsOpenFileChannel(cmdInterp, pathPtr, mode, permissions) } else { /* Leave an error message if the cmdInterp is non NULL */ if (cmdInterp != NULL) { - int posixError = -1; - Tcl_Obj* error = Tcl_GetObjResult(interp); - if (Tcl_GetIntFromObj(NULL, error, &posixError) == TCL_OK) { - Tcl_SetErrno(posixError); + if (returnVal == -1) { Tcl_ResetResult(cmdInterp); Tcl_AppendResult(cmdInterp, "couldn't open \"", Tcl_GetString(pathPtr), "\": ", Tcl_PosixError(interp), (char *) NULL); - } else { + Tcl_Obj* error = Tcl_GetObjResult(interp); /* * Copy over the error message to cmdInterp, * duplicating it in case of threading issues. @@ -1319,7 +1316,8 @@ VfsOpenFileChannel(cmdInterp, pathPtr, mode, permissions) channelRet->interp = interp; channelRet->closeCallback = closeCallback; /* The channelRet structure will be freed in the callback */ - Tcl_CreateCloseHandler(chan, &VfsCloseProc, (ClientData)channelRet); + Tcl_CreateCloseHandler(chan, &VfsCloseProc, + (ClientData)channelRet); } } return chan; @@ -1399,7 +1397,8 @@ VfsMatchInDirectory( if (pattern == NULL) { Tcl_ListObjAppendElement(interp, mountCmd, Tcl_NewObj()); } else { - Tcl_ListObjAppendElement(interp, mountCmd, Tcl_NewStringObj(pattern,-1)); + Tcl_ListObjAppendElement(interp, mountCmd, + Tcl_NewStringObj(pattern,-1)); } Tcl_ListObjAppendElement(interp, mountCmd, Tcl_NewIntObj(type)); Tcl_SaveResult(interp, &savedResult); @@ -1427,7 +1426,7 @@ VfsMatchInDirectory( static int VfsDeleteFile( - Tcl_Obj *pathPtr) /* Pathname of file to be removed (UTF-8). */ + Tcl_Obj *pathPtr) /* Pathname of file to be removed */ { Tcl_Obj *mountCmd = NULL; Tcl_SavedResult savedResult; @@ -1450,7 +1449,7 @@ VfsDeleteFile( static int VfsCreateDirectory( - Tcl_Obj *pathPtr) /* Pathname of directory to create (UTF-8). */ + Tcl_Obj *pathPtr) /* Pathname of directory to create */ { Tcl_Obj *mountCmd = NULL; Tcl_SavedResult savedResult; @@ -1833,7 +1832,8 @@ VfsBuildCommandForPath(Tcl_Interp **iRef, CONST char* cmd, Tcl_Obj *pathPtr) { } else { Tcl_ListObjAppendElement(NULL, mountCmd, Tcl_NewStringObj(normedString,splitPosition)); - if ((normedString[splitPosition] != VFS_SEPARATOR) || (VFS_SEPARATOR ==':')) { + if ((normedString[splitPosition] != VFS_SEPARATOR) + || (VFS_SEPARATOR ==':')) { /* This will occur if we mount 'ftp://' */ splitPosition--; } diff --git a/library/httpvfs.tcl b/library/httpvfs.tcl index d6f30dd..cf1bec0 100644 --- a/library/httpvfs.tcl +++ b/library/httpvfs.tcl @@ -82,7 +82,7 @@ proc vfs::http::stat {dirurl name} { proc vfs::http::access {dirurl name mode} { ::vfs::log "access $name $mode" if {$mode & 2} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } if {$name == ""} { return 1 } set state [::http::geturl "$dirurl$name"] @@ -117,7 +117,7 @@ proc vfs::http::open {dirurl name mode permissions} { } "a" - "w*" { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } default { return -code error "illegal access mode \"$mode\"" @@ -144,17 +144,17 @@ proc vfs::http::matchindirectory {dirurl path actualpath pattern type} { proc vfs::http::createdirectory {dirurl name} { ::vfs::log "createdirectory $name" - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } proc vfs::http::removedirectory {dirurl name} { ::vfs::log "removedirectory $name" - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } proc vfs::http::deletefile {dirurl name} { ::vfs::log "deletefile $name" - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } proc vfs::http::fileattributes {dirurl path args} { @@ -172,12 +172,12 @@ proc vfs::http::fileattributes {dirurl path args} { # set value set index [lindex $args 0] set val [lindex $args 1] - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } } } proc vfs::http::utime {dirurl path actime mtime} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } diff --git a/library/mk4vfs.tcl b/library/mk4vfs.tcl index 471ce6b..1f81d76 100644 --- a/library/mk4vfs.tcl +++ b/library/mk4vfs.tcl @@ -120,7 +120,7 @@ namespace eval vfs::mk4 { proc access {db name mode} { if {$mode & 2} { if {$::mk4vfs::v::mode($db) == "readonly"} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } } # We can probably do this more efficiently, can't we? @@ -165,7 +165,7 @@ namespace eval vfs::mk4 { } a { if {$::mk4vfs::v::mode($db) == "readonly"} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } if { [catch {::mk4vfs::stat $db $file sb }] } { # Create file @@ -204,7 +204,7 @@ namespace eval vfs::mk4 { } w* { if {$::mk4vfs::v::mode($db) == "readonly"} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } if { [catch {::mk4vfs::stat $db $file sb }] } { # Create file @@ -260,7 +260,7 @@ namespace eval vfs::mk4 { 2 { # set value if {$::mk4vfs::mode($db) == "readonly"} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } set index [lindex $args 0] set val [lindex $args 1] @@ -496,7 +496,7 @@ namespace eval mk4vfs { proc mkdir {db path} { if {$v::mode($db) == "readonly"} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } set sp [::file split $path] set parent 0 @@ -542,7 +542,7 @@ namespace eval mk4vfs { proc mtime {db path time} { if {$v::mode($db) == "readonly"} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } stat $db $path sb if { $sb(type) == "file" } { @@ -554,7 +554,7 @@ namespace eval mk4vfs { proc delete {db path {recursive 0}} { #puts stderr "mk4delete db $db path $path recursive $recursive" if {$v::mode($db) == "readonly"} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } stat $db $path sb if {$sb(type) == "file" } { diff --git a/library/tarvfs.tcl b/library/tarvfs.tcl index 556758f..b042a57 100644 --- a/library/tarvfs.tcl +++ b/library/tarvfs.tcl @@ -73,7 +73,7 @@ proc vfs::tar::stat {tarfd name} { proc vfs::tar::access {tarfd name mode} { if {$mode & 2} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } # Readable, Exists and Executable are treated as 'exists' # Could we get more information from the archive? @@ -95,7 +95,7 @@ proc vfs::tar::open {tarfd name mode permissions} { "" - "r" { if {![::tar::exists $tarfd $name]} { - return -code error $::vfs::posix(ENOENT) + vfs::filesystem posixerror $::vfs::posix(ENOENT) } ::tar::stat $tarfd $name sb @@ -114,24 +114,24 @@ proc vfs::tar::open {tarfd name mode permissions} { return [list $nfd] } default { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } } } proc vfs::tar::createdirectory {tarfd name} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) #error "tar-archives are read-only (not implemented)" } proc vfs::tar::removedirectory {tarfd name} { #::vfs::log "removedirectory $name" - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) #error "tar-archives are read-only (not implemented)" } proc vfs::tar::deletefile {tarfd name} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) #error "tar-archives are read-only (not implemented)" } @@ -152,14 +152,14 @@ proc vfs::tar::fileattributes {tarfd name args} { # set value set index [lindex $args 0] set val [lindex $args 1] - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } } } # set the 'mtime' of a file. proc vfs::tar::utime {fd path actime mtime} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } # diff --git a/library/zipvfs.tcl b/library/zipvfs.tcl index 62d636c..5906abb 100644 --- a/library/zipvfs.tcl +++ b/library/zipvfs.tcl @@ -73,7 +73,7 @@ proc vfs::zip::stat {zipfd name} { proc vfs::zip::access {zipfd name mode} { #::vfs::log "zip-access $name $mode" if {$mode & 2} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } # Readable, Exists and Executable are treated as 'exists' # Could we get more information from the archive? @@ -96,7 +96,7 @@ proc vfs::zip::open {zipfd name mode permissions} { "" - "r" { if {![::zip::exists $zipfd $name]} { - return -code error $::vfs::posix(ENOENT) + vfs::filesystem posixerror $::vfs::posix(ENOENT) } ::zip::stat $zipfd $name sb @@ -114,24 +114,24 @@ proc vfs::zip::open {zipfd name mode permissions} { return [list $nfd] } default { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } } } proc vfs::zip::createdirectory {zipfd name} { #::vfs::log "createdirectory $name" - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } proc vfs::zip::removedirectory {zipfd name} { #::vfs::log "removedirectory $name" - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } proc vfs::zip::deletefile {zipfd name} { #::vfs::log "deletefile $name" - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } proc vfs::zip::fileattributes {zipfd name args} { @@ -150,13 +150,13 @@ proc vfs::zip::fileattributes {zipfd name args} { # set value set index [lindex $args 0] set val [lindex $args 1] - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } } } proc vfs::zip::utime {fd path actime mtime} { - return -code error [vfs::filesystem posixerror $::vfs::posix(EROFS)] + vfs::filesystem posixerror $::vfs::posix(EROFS) } # Below copied from TclKit distribution