Skip to content

Commit

Permalink
DA-992: Pair windows' delete + create event to generate a rename event (
Browse files Browse the repository at this point in the history
#1)

* made the changes related to recursive directory check

* made changes in window.go for buffer size

* added the oldname attribute

* old name added to rename event, one event is generated for rename

* added oldname in printing rename events

* tests for checking  the oldName attr for rename added

* create fsnotify event added

* input to create event changed

* create fsnotify event function modified

* ID added

* logs added

* added create fsnotify event in inotify

* logs added

* prints added

* reviews

* reviews addressed

* Hangkun/da 992/window rename event (#2)

* Let's begin

* Add getpath

* Init test workflow

* 1.40.0 exits?

* Linter fix

* asdf

* 100

Co-authored-by: hu13 <hangkun@preveil.com>

* Clean up unused

* Badge

Co-authored-by: Hangkun Ung <hangkun.ung@gmail.com>
Co-authored-by: hu13 <hangkun@preveil.com>
  • Loading branch information
3 people committed Jul 14, 2021
1 parent 57f1a48 commit 580c3c9
Show file tree
Hide file tree
Showing 9 changed files with 412 additions and 67 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -1 +1,2 @@
go.sum linguist-generated
*.go text eol=lf
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,47 @@
name: CI
on:
push:
branches:
- preveil
pull_request:

jobs:

test:
name: Unit tests

runs-on: windows-latest

steps:
- name: Set up Go 1.13
uses: actions/setup-go@v2
with:
go-version: 1.13

- name: Check out code into the Go module directory
if: github.event_name == 'push'
uses: actions/checkout@v2

- name: Checkout pr's head commit
if: github.event_name == 'pull_request'
uses: actions/checkout@v2
with:
# on pull_request, we don't want to build on
# the merged commit
ref: ${{ github.event.pull_request.head.sha }}

- name: Run unit tests
run: make test

golangci:
name: Linter
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.40.0

args: --config golangci.yml ./...
57 changes: 57 additions & 0 deletions Makefile
@@ -0,0 +1,57 @@
define USAGE
USAGE:
> make [
test: run all unit tests
test-unit: run all unit tests
lint: run golangci-linter

clean: clean test cache and other deps

help: print this help message
]
endef
export USAGE

SHELL := /bin/bash

BIN := $(PWD)/bin
GO := go
GOTEST := $(BIN)/gotest
LINT := $(BIN)/golangci-lint

export PATH := $(PATH):$(BIN)

help:
@echo "$$USAGE"

usage:
@echo "$$USAGE"

sense:
@echo "$$USAGE"

install-dep-tools:
GOBIN=$(BIN) $(GO) get -u github.com/rakyll/gotest
@make install-golangci-lint

install-golangci-lint:
# binary will be $(BIN)
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(BIN) v1.40.0

test: test-unit

test-unit: install-dep-tools testclean
$(GOTEST) ./... -v -race

testclean:
$(GO) clean -testcache || true

clean: testclean
rm -rf $(BIN)/*
$(GO) clean -cache
$(GO) clean -modcache

lint: install-dep-tools
$(LINT) run --config golangci.yml ./...

ci: test lint
4 changes: 3 additions & 1 deletion README.md
@@ -1,3 +1,5 @@
![](https://github.com/PreVeil/fsnotify/workflows/CI/badge.svg)

# File system notifications for Go

[![GoDoc](https://godoc.org/github.com/fsnotify/fsnotify?status.svg)](https://godoc.org/github.com/fsnotify/fsnotify) [![Go Report Card](https://goreportcard.com/badge/github.com/fsnotify/fsnotify)](https://goreportcard.com/report/github.com/fsnotify/fsnotify)
Expand Down Expand Up @@ -27,7 +29,7 @@ Please see [the documentation](https://godoc.org/github.com/fsnotify/fsnotify) a

## API stability

fsnotify is a fork of [howeyc/fsnotify](https://godoc.org/github.com/howeyc/fsnotify) with a new API as of v1.0. The API is based on [this design document](http://goo.gl/MrYxyA).
fsnotify is a fork of [howeyc/fsnotify](https://godoc.org/github.com/howeyc/fsnotify) with a new API as of v1.0. The API is based on [this design document](http://goo.gl/MrYxyA).

All [releases](https://github.com/fsnotify/fsnotify/releases) are tagged based on [Semantic Versioning](http://semver.org/). Further API changes are [planned](https://github.com/fsnotify/fsnotify/milestones), and will be tagged with a new major revision number.

Expand Down
12 changes: 9 additions & 3 deletions fsnotify.go
Expand Up @@ -15,8 +15,10 @@ import (

// Event represents a single file system notification.
type Event struct {
Name string // Relative path to the file or directory.
Op Op // File operation that triggered the event.
Name string // Relative path to the file or directory.
Op Op // File operation that triggered the event.
OldName string
ID uint64
}

// Op describes a set of file operations.
Expand Down Expand Up @@ -59,7 +61,11 @@ func (op Op) String() string {
// String returns a string representation of the event in the form
// "file: REMOVE|WRITE|..."
func (e Event) String() string {
return fmt.Sprintf("%q: %s", e.Name, e.Op.String())
return fmt.Sprintf("newpath=%s, oldpath=%s, op=%s, eventID=%d", e.Name, e.OldName, e.Op.String(), e.ID)
}

func (e Event) GetPath() string {
return e.Name
}

// Common errors that can be reported by a watcher
Expand Down
20 changes: 14 additions & 6 deletions fsnotify_test.go
Expand Up @@ -7,23 +7,31 @@
package fsnotify

import (
"fmt"
"os"
"testing"
"time"
)

func TestEventStringWithValue(t *testing.T) {
formatEvent := func(name, oldName string, op Op, id uint64) string {
return fmt.Sprintf("newpath=%s, oldpath=%s, op=%s, eventID=%d", name, oldName, op.String(), id)
}
for opMask, expectedString := range map[Op]string{
Chmod | Create: `"/usr/someFile": CREATE|CHMOD`,
Rename: `"/usr/someFile": RENAME`,
Remove: `"/usr/someFile": REMOVE`,
Write | Chmod: `"/usr/someFile": WRITE|CHMOD`,
Chmod | Create: formatEvent("/usr/someFile", "", Create|Chmod, 0),
Rename: formatEvent("/usr/someFile", "", Rename, 0),
Remove: formatEvent("/usr/someFile", "", Remove, 0),
Write | Chmod: formatEvent("/usr/someFile", "", Write|Chmod, 0),
} {
event := Event{Name: "/usr/someFile", Op: opMask}
event := Event{Name: "/usr/someFile", Op: opMask, OldName: "", ID: 0}
if event.String() != expectedString {
t.Fatalf("Expected %s, got: %v", expectedString, event.String())
}

}
renameEvent := Event{Name: "/usr/someFile_Rename", Op: Rename, OldName: "/usr/someFile", ID: 123}
renameEventExpectedString := formatEvent("/usr/someFile_Rename", "/usr/someFile", Rename, 123)
if renameEvent.String() != renameEventExpectedString {
t.Fatalf("Expected %s, got: %v", renameEventExpectedString, renameEvent.String())
}
}

Expand Down
23 changes: 23 additions & 0 deletions golangci.yml
@@ -0,0 +1,23 @@
run:
deadline: 2m

# all available settings of specific linters
linters-settings:
nolintlint:
# Enable to require an explanation of nonzero length after each nolint directive. Default is false.
require-explanation: true

linters:
disable-all: true
enable:
- gofmt
- goimports
- gosimple
- ineffassign
- misspell
- govet
- nolintlint
- whitespace
- dupl
- rowserrcheck
- unparam

0 comments on commit 580c3c9

Please sign in to comment.