Handle symlinks by making them behave like hardlinks

This commit is contained in:
Harshavardhana
2015-05-26 19:06:29 -07:00
parent 0d03b7838f
commit a65f431004
2 changed files with 30 additions and 8 deletions
+28 -6
View File
@@ -170,7 +170,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
}
defer dir.Close()
fi, err := os.Lstat(f.path)
fi, err := os.Stat(fpath)
if err != nil {
contentCh <- client.ContentOnChannel{
Content: nil,
@@ -195,11 +195,23 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
return
}
for _, file := range files {
var fi os.FileInfo
fi = file
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
fi, err = os.Stat(filepath.Join(dir.Name(), file.Name()))
if err != nil {
contentCh <- client.ContentOnChannel{
Content: nil,
Err: iodine.New(err, nil),
}
return
}
}
content := &client.Content{
Name: file.Name(),
Time: file.ModTime(),
Size: file.Size(),
Type: file.Mode(),
Name: fi.Name(),
Time: fi.ModTime(),
Size: fi.Size(),
Type: fi.Mode(),
}
contentCh <- client.ContentOnChannel{
Content: content,
@@ -208,7 +220,7 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
}
default:
content := &client.Content{
Name: dir.Name(),
Name: f.path,
Time: fi.ModTime(),
Size: fi.Size(),
Type: fi.Mode(),
@@ -223,6 +235,10 @@ func (f *fsClient) listInRoutine(contentCh chan client.ContentOnChannel) {
func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel) {
defer close(contentCh)
visitFS := func(fp string, fi os.FileInfo, err error) error {
// fp also sends back itself with visitFS, ignore it we don't need it
if fp == f.path {
return nil
}
if err != nil {
if strings.Contains(err.Error(), "operation not permitted") ||
// os.IsNotExist(err) ||
@@ -231,6 +247,12 @@ func (f *fsClient) listRecursiveInRoutine(contentCh chan client.ContentOnChannel
}
return iodine.New(err, nil) // abort
}
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
fi, err = os.Stat(fp)
if err != nil {
return iodine.New(err, nil)
}
}
content := &client.Content{
Name: fp,
Time: fi.ModTime(),
+2 -2
View File
@@ -182,7 +182,7 @@ var (
if NoJSONPrint {
println(themesDB[currThemeName].Error, data[i])
if !NoDebugPrint {
print(themesDB[currThemeName].Error, err)
println(themesDB[currThemeName].Error, err)
}
return
}
@@ -236,7 +236,7 @@ var (
if NoJSONPrint {
println(themesDB[currThemeName].Error, data[i])
if !NoDebugPrint {
print(themesDB[currThemeName].Error, err)
println(themesDB[currThemeName].Error, err)
}
return
}