Re: symbolic link problem



At 2008-06-24 08:26AM, "Eric Hassold" wrote:
So, to detect a broken link, you may use:

I can't resist commenting on this proc.

proc brokenlink {f} {
if {![catch {file type $f} ftype]} {

[file type] will only throw an error if $f does not exist (as far as I
know). I think that's something the caller would want to know, so I'd
let that error propagate up.

if {$ftype eq "link" && ![file exists $f]} {

You probably meant to use [file exists [file readlink $f]] there

return 1
}
}

return 0
}


How about:

proc is_broken {linkname} {
return [expr { ! [file exists [file readlink $linkname]]]
}

It will error if $linkname does not exist or is not a link file, so:

set rc [catch {is_broken $filename} result]
if {$rc == 0 && $result} {
puts "$filename is a broken link"
} elseif {$rc == 0} {
puts "link $filename is OK"
} else {
puts "not a link: $result"
}

--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
.



Relevant Pages