prsdmfanotify

package module
v0.0.0-...-518d0d4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

README

prsdm-fanotify

TBD

Example main.go

package main

import (
  "os"
  "os/signal"
  "strings"

  "github.com/gianniszach/prsdm-fanotify"
)

func main() {
	fileChangeChan := make(chan prsdmfanotify.FileChange, 100)
	go prsdmfanotify.Listen("/root/work/giannis/fswatch-test/", isFiltered, fileChangeChan)

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	for range c {
		break
	}
}

func isFiltered(path string) bool {
  if strings.HasPrefix(path, "/var") {
    return true
  }
  if strings.HasPrefix(path, "/tmp") {
    return true
  }
  if strings.HasPrefix(path, "/root/work/giannis/") {
    return false
  }
  return true
}

example go.mod:

module fswatch

go 1.20

require (
	github.com/gianniszach/prsdm-fanotify v0.0.0-20230517123316-6a34de5ddd7d
	golang.org/x/sys v0.7.0
)

Documentation

Overview

Modified version of https://github.com/ozeidan/gosearch/blob/master/internal/fanotify/fanotify.go Changes: - support for modified files - support for attributes change

Index

Constants

View Source
const (
	// Creation of a file/directory
	Creation = iota
	// Deletion of a file/directory
	Deletion
)

Variables

This section is empty.

Functions

func Listen

func Listen(
	listenDir string,
	isFiltered func(path string) bool,
	changeReceiver chan<- FileChange,
) error

Listen starts listening for created/deleted/moved files in the whole file system changeReceiver is a channel that FileChange structs, which describe the events, will be sent through

Types

type FileChange

type FileChange struct {
	FolderPath string
	ChangeType int
}

FileChange describes the event of changes in a directory FolderPath is the path of the directory Changetype is either Creation or Deletion

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL