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

Add watch dir recursive option #210

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,12 @@ github.com/drone/envsubst v1.0.3 h1:PCIBwNDYjs50AsLZPYdfhSATKaRg/FJmDc2D6+C2x8g=
github.com/drone/envsubst v1.0.3/go.mod h1:N2jZmlMufstn1KEqvbHjw40h1KyTmnVzHcSc9bFiJ2g=
github.com/dvyukov/go-fuzz v0.0.0-20210103155950-6a8e9d1f2415 h1:q1oJaUPdmpDm/VyXosjgPgr6wS7c5iV2p0PwJD73bUI=
github.com/dvyukov/go-fuzz v0.0.0-20210103155950-6a8e9d1f2415/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw=
github.com/e2b-dev/fsnotify v0.0.0-20241202191622-2cae6c99fd56 h1:mzTVxfzZjgu+yXKaMPuHHoiu9dTdXVfOkLWLXMFZ5io=
github.com/e2b-dev/fsnotify v0.0.0-20241202191622-2cae6c99fd56/go.mod h1:49MToyZ6q0q2rwa5A77Gdh9p3gqmoID22vEJeAYyNDs=
github.com/e2b-dev/fsnotify v0.0.0-20241216144736-0d773a6a878f h1:lDK0AOq8wIL0kP00qo5SEkw8rFEbNoT7q034oBfUcxk=
github.com/e2b-dev/fsnotify v0.0.0-20241216144736-0d773a6a878f/go.mod h1:49MToyZ6q0q2rwa5A77Gdh9p3gqmoID22vEJeAYyNDs=
github.com/e2b-dev/fsnotify v0.0.0-20241216145137-2fe5d32bcb51 h1:eo4W23CTT43LdwJ5i+CCYZrsu/c4BkK7JGG5ozrwNuA=
github.com/e2b-dev/fsnotify v0.0.0-20241216145137-2fe5d32bcb51/go.mod h1:49MToyZ6q0q2rwa5A77Gdh9p3gqmoID22vEJeAYyNDs=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-resiliency v1.3.0 h1:RRL0nge+cWGlxXbUzJ7yMcq6w2XBEr19dCN6HECGaT0=
github.com/eapache/go-resiliency v1.3.0/go.mod h1:5yPzW0MIvSe0JDsv0v+DvcjEv2FyD6iZYSs1ZI+iQho=
Expand Down
10 changes: 0 additions & 10 deletions packages/buckets/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@ resource "google_storage_bucket" "public_builds_storage_bucket" {
soft_delete_policy {
retention_duration_seconds = 0
}

lifecycle_rule {
condition {
age = 8
}

action {
type = "Delete"
}
}
}

resource "google_storage_bucket_iam_member" "public_builds_storage_bucket_iam" {
Expand Down
2 changes: 1 addition & 1 deletion packages/envd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/creack/pty v1.1.18
github.com/deepmap/oapi-codegen/v2 v2.1.1-0.20240519200907-da9077bb5ffe
github.com/e2b-dev/infra/packages/shared v0.0.0
github.com/fsnotify/fsnotify v1.7.0
github.com/e2b-dev/fsnotify v0.0.0-20241216145137-2fe5d32bcb51
github.com/go-chi/chi/v5 v5.0.12
github.com/oapi-codegen/runtime v1.1.1
github.com/rs/cors v1.11.0
Expand Down
5 changes: 3 additions & 2 deletions packages/envd/internal/services/filesystem/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
"github.com/e2b-dev/infra/packages/envd/internal/logs"
"github.com/e2b-dev/infra/packages/envd/internal/permissions"
rpc "github.com/e2b-dev/infra/packages/envd/internal/services/spec/filesystem"
"github.com/e2b-dev/infra/packages/envd/internal/utils"

"connectrpc.com/connect"
"github.com/fsnotify/fsnotify"
"github.com/e2b-dev/fsnotify"
)

func (s Service) WatchDir(ctx context.Context, req *connect.Request[rpc.WatchDirRequest], stream *connect.ServerStream[rpc.WatchDirResponse]) error {
Expand Down Expand Up @@ -48,7 +49,7 @@ func (s Service) watchHandler(ctx context.Context, req *connect.Request[rpc.Watc
}
defer w.Close()

err = w.Add(watchPath)
err = w.Add(utils.FsnotifyPath(watchPath, req.Msg.Recursive))
if err != nil {
return connect.NewError(connect.CodeInternal, fmt.Errorf("error adding path %s to watcher: %w", watchPath, err))
}
Expand Down
9 changes: 5 additions & 4 deletions packages/envd/internal/services/filesystem/watch_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import (
"sync"

"connectrpc.com/connect"
"github.com/fsnotify/fsnotify"
"github.com/e2b-dev/fsnotify"
"github.com/rs/zerolog"

"github.com/e2b-dev/infra/packages/envd/internal/logs"
"github.com/e2b-dev/infra/packages/envd/internal/permissions"
rpc "github.com/e2b-dev/infra/packages/envd/internal/services/spec/filesystem"
"github.com/e2b-dev/infra/packages/envd/internal/utils"
"github.com/e2b-dev/infra/packages/shared/pkg/id"
)

Expand All @@ -26,13 +27,13 @@ type FileWatcher struct {
Lock sync.Mutex
}

func CreateFileWatcher(watchPath, operationID string, logger *zerolog.Logger) (*FileWatcher, error) {
func CreateFileWatcher(watchPath string, recursive bool, operationID string, logger *zerolog.Logger) (*FileWatcher, error) {
w, err := fsnotify.NewWatcher()
if err != nil {
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("error creating watcher: %w", err))
}

err = w.Add(watchPath)
err = w.Add(utils.FsnotifyPath(watchPath, recursive))
if err != nil {
_ = w.Close()
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("error adding path %s to watcher: %w", watchPath, err))
Expand Down Expand Up @@ -156,7 +157,7 @@ func (s Service) CreateWatcher(ctx context.Context, req *connect.Request[rpc.Cre

watcherId := "w" + id.Generate()

w, err := CreateFileWatcher(watchPath, watcherId, s.logger)
w, err := CreateFileWatcher(watchPath, req.Msg.Recursive, watcherId, s.logger)
s.watchers.Store(watcherId, w)

return connect.NewResponse(&rpc.CreateWatcherResponse{
Expand Down
Loading