Am I overlooking something obvious?
Or perhaps I'm misunderstanding, and you mean to request that the root
of the walk be treated specially, and that symlinks be followed when
looking at the root, but not during the walk itself?
David
--
David Roundy
I though the OP was saying that when they got a symlink from
Walk they were unable to construct the full path for the referred-to
file so as to be able to Walk it.
Minimal complete example would be nice.
> On Fri, Jan 21, 2011 at 12:16 AM, David Symonds <dsym...@golang.org> wrote:
>> path.Walk uses os.Lstat and thus doesn't work on a symlink to a directory.
>> If I use os.Lstat or os.Stat to try to dereference a symlink, I don't
>> think I can get a full filename to pass to path.Walk without a lot of
>> effort.
>>
>> Am I overlooking something obvious?
Chris
--
Chris "allusive" Dollin
> Or perhaps I'm misunderstanding, and you mean to request that the root
> of the walk be treated specially, and that symlinks be followed when
> looking at the root, but not during the walk itself?
Yes, that's precisely the situation. I'm working with a build system
that creates a regular directory tree in a place that isn't practical
to locate and creates a symlink to the root of that tree in a
convenient location. I've got the path to the symlink, and I want to
walk the directory tree.
Any ideas?
Dave.
Are you trying to avoid writing a function such as this?
func indirect(p string) (string, os.Error) {
fi, err := os.Lstat(p)
if err != nil {
return "", err
}
for fi.IsSymlink() {
t, err := os.Readlink(p)
if err != nil {
return "", err
}
if path.IsAbs(t) {
p = t
} else {
dir, _ := path.Split(p)
p = path.Join(dir, t)
}
fi, err = os.Lstat(p)
if err != nil {
return "", err
}
}
return p, nil
}
Perhaps there is a place for this in the standard path package.
kr
Note that this particular function doesn't check for link cycles, so
it's not safe in general.
kr
> Are you trying to avoid writing a function such as this?
Yeah, I was trying to avoid that much effort. It seems a bit tricky to
get right, what with all the relative vs. absolute paths.
You're right, I think there should be something like this in the
standard library; path does seem like a reasonable place.
Dave.