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

remove GetFdName(), use file.Name() instead. #1

Closed
wants to merge 1 commit 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
26 changes: 1 addition & 25 deletions lock_file_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,6 @@ func (file *LockFile) Remove() error {
return err
}

name, err := GetFdName(file.Fd())
if err != nil {
return err
}

err = syscall.Unlink(name)
err := syscall.Unlink(file.Name())
return err
}

// GetFdName returns file name for given descriptor.
func GetFdName(fd uintptr) (name string, err error) {
path := fmt.Sprintf("/proc/self/fd/%d", int(fd))

var (
fi os.FileInfo
n int
)
if fi, err = os.Lstat(path); err != nil {
return
}
buf := make([]byte, fi.Size()+1)

if n, err = syscall.Readlink(path, buf); err == nil {
name = string(buf[:n])
}
return
}
17 changes: 1 addition & 16 deletions lock_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,6 @@ func TestNewLockFile(test *testing.T) {
}
}

func TestGetFdName(test *testing.T) {
name, err := GetFdName(0)
if err != nil {
test.Error(err)
} else {
if name != "/dev/null" {
test.Errorf("Filename of fd 0: `%s'", name)
}
}

name, err = GetFdName(1011)
if err == nil {
test.Errorf("GetFdName(): Error was not detected on invalid fd, name: `%s'", name)
}
}

func TestReadPid(test *testing.T) {
lock, err := CreatePidFile(filename, fileperm)
if err != nil {
Expand Down Expand Up @@ -118,6 +102,7 @@ func TestLockFileLock(test *testing.T) {
if err != nil {
test.Fatal(err)
}
fmt.Print(msg)
if msg != "locked" {
test.Fatal("script can not lock file")
}
Expand Down