Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

wrong feedback from file writable

Status
Not open for further replies.

reggler

Programmer
Nov 13, 2008
63
CA
Hi There,

I wanna test if I have permissions to write a file on a Windows share like this:
Code:
proc finaltest::retrieve {target perm startTime} {
	# replace any forward slashes with backslashes
	regsub -all {/} $target {\\} target	
	# Check if we have requested write permissions to file
	set wrtbl [file writable $target]
	set wrreq [string first "w" $perm]
	if { $wrreq > -1 && $wrtbl == 0} {
		GUI::Error_DialogWIN "Permission denied, no write access to file\n$target\nrequested permissions: $perm\nwrreq: $wrreq wrtbl: $wrtbl"
		return NO_ACCESS
	}
and when i run this, I always get back to not have permissions to write but when i navigate with windows explorer to given location - i can properly access files(rwx)!
What's wrong here?

Thanks for any hints!

Ron
Hours of planing can save weeks of coding
 
Just a shot in the dark, but how are you getting perm and have you checked it's value inside the proc?

Anyway, your condition is $wrreq > -1 AND writable returns False. That means w was found in perm. Is that what you meant?

_________________
Bob Rashkin
 
yes exactly, when w (write) is requested in $perm (which would make wrreq > -1), I want to check if the file is writable.
Also, i need to check the value of $perm before releasing this code, right.
But you know, this is 'just' development code anyways ...

Any other suggestions?
Thanks anyways

Ron
Hours of planing can save weeks of coding
 
So what is the value of perm that is passed into the proc?

_________________
Bob Rashkin
 
just w

Ron
Hours of planing can save weeks of coding
 
OK. If you're sure that $perm is being passed into the proc as "w", then there must be a permissions disconnect between you as user and Tcl. Just for jollies, I'd go into into a Tcl shell and query the file ($target) to see if it's writable. Then, when it inevitably says it isn't, try writing to it anyway.

_________________
Bob Rashkin
 
Well, till now the proc looked like this:
Code:
proc finaltest::retrieve {target perm startTime} {
    #puts "begin to run finaltest::retrieve($target $perm $startTime)"
    while {[expr $startTime+$finaltest::const(FILE_TIMEOUT)]>[clock seconds]} {
        if ![catch {open $target $perm} fileId] {return $fileId}
        after 2000
    }
    GUI::displayError 3
    #puts "finished finaltest::retrieve($target $perm $startTime)"
    return TIMEOUT
}
and that's been working fine but anyhow I came and I was like uhm, i need to check if the file is writable at all first if a write is requested and also if /-es are passed we need to replace them with \-es. That's how i came up with my "improvment" that's not working for some weird reason... :eek:

Ron
Hours of planing can save weeks of coding
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top