This repository was archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bb101e0
Speed up event processing by introducing duplicate cache
ammario 2288735
Process safe events concurrently
ammario ba23ea5
Remove single file support
ammario c2ca1ea
Improve replace message
ammario ed23f64
Document test command
ammario c305b9d
Improve dropped event calculation
ammario 4e31fe9
Add DEBUG_RSYNC env
ammario a675d5e
Create watch before initial sync
ammario 423278b
Support file deletion again
ammario 65be003
Add semaphore to pushing
ammario 4905bbd
Change initial sync to Success level
ammario b0c4bc3
Comment on dir translation
ammario File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package sync | ||
|
||
import ( | ||
"os" | ||
"time" | ||
|
||
"github.com/rjeczalik/notify" | ||
"go.coder.com/flog" | ||
) | ||
|
||
type timedEvent struct { | ||
CreatedAt time.Time | ||
notify.EventInfo | ||
} | ||
|
||
type eventCache map[string]timedEvent | ||
|
||
func (cache eventCache) Add(ev timedEvent) { | ||
log := flog.New() | ||
log.Prefix = ev.Path() + ": " | ||
lastEvent, ok := cache[ev.Path()] | ||
if ok { | ||
switch { | ||
// If the file was quickly created and then destroyed, pretend nothing ever happened. | ||
case lastEvent.Event() == notify.Create && ev.Event() == notify.Remove: | ||
delete(cache, ev.Path()) | ||
log.Info("ignored Create then Remove") | ||
return | ||
} | ||
log.Info("replaced %s with %s", lastEvent.Event(), ev.Event()) | ||
} | ||
// Only let the latest event for a path have action. | ||
cache[ev.Path()] = ev | ||
} | ||
|
||
// SequentialEvents returns the list of events that pertain to directories. | ||
// The set of returned events is disjoint with ConcurrentEvents. | ||
func (cache eventCache) SequentialEvents() []timedEvent { | ||
var r []timedEvent | ||
for _, ev := range cache { | ||
info, err := os.Stat(ev.Path()) | ||
if err == nil && !info.IsDir() { | ||
continue | ||
} | ||
// Include files that have deleted here. | ||
// It's unclear whether they're files or folders. | ||
r = append(r, ev) | ||
|
||
} | ||
return r | ||
} | ||
|
||
// ConcurrentEvents returns the list of events that are safe to process after SequentialEvents. | ||
// The set of returns events is disjoint with SequentialEvents. | ||
func (cache eventCache) ConcurrentEvents() []timedEvent { | ||
var r []timedEvent | ||
for _, ev := range cache { | ||
info, err := os.Stat(ev.Path()) | ||
if err != nil { | ||
continue | ||
} | ||
if info.IsDir() { | ||
continue | ||
} | ||
r = append(r, ev) | ||
|
||
} | ||
return r | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package sync | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"golang.org/x/crypto/ssh/terminal" | ||
) | ||
|
||
func setConsoleTitle(title string) { | ||
if !terminal.IsTerminal(int(os.Stdout.Fd())) { | ||
return | ||
} | ||
fmt.Printf("\033]0;%s\007", title) | ||
} | ||
|
||
|
||
func fmtUpdateTitle(path string) string { | ||
return "🚀 updating " + filepath.Base(path) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't hurt to comment on why this is necessary