Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for symlink #76

Open
asafsemo opened this issue Jul 24, 2019 · 0 comments
Open

Added support for symlink #76

asafsemo opened this issue Jul 24, 2019 · 0 comments

Comments

@asafsemo
Copy link

I update the code to support symlink files.
If the folder includes symlink it will follow and monitor the pointed file.

func (w *Watcher) list(name string) (map[string]os.FileInfo, error) {
fileList := make(map[string]os.FileInfo)

// Make sure name exists.
stat, err := os.Stat(name)
if err != nil {
	return nil, err
}

fileList[name] = stat

// If it's not a directory, just return.
if !stat.IsDir() {
	return fileList, nil
}

// It's a directory.
fInfoList, err := ioutil.ReadDir(name)
if err != nil {
	return nil, err
}
// Add all of the files in the directory to the file list as long
// as they aren't on the ignored list or are hidden files if ignoreHidden
// is set to true.

outer:
for _, fInfo := range fInfoList {
path := filepath.Join(name, fInfo.Name())
_, ignored := w.ignored[path]

	isHidden, err := isHiddenFile(path)
	if err != nil {
		return nil, err
	}

	if ignored || (w.ignoreHidden && isHidden) {
		continue
	}

	for _, f := range w.ffh {
		err := f(fInfo, path)
		if err == ErrSkip {
			continue outer
		}
		if err != nil {
			return nil, err
		}
	}

	// asaf: handle symlink files
	for fInfo.Mode()&os.ModeSymlink != 0 {
		link, err1 := os.Readlink(path)
		if err1 != nil {
			continue outer
		}
		fInfo, err1 = os.Stat(link)
		if err1 != nil {
			continue outer
		}
	}
            // asaf: end update

	fileList[path] = fInfo
}
return fileList, nil

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant