vendor: add qingstor-sdk-go for QingStor
This commit is contained in:
parent
f682002b84
commit
466dd22b44
136 changed files with 15952 additions and 1 deletions
49
vendor/github.com/pengsrc/go-shared/pid/pidfile.go
generated
vendored
Normal file
49
vendor/github.com/pengsrc/go-shared/pid/pidfile.go
generated
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Package pid provides structure and helper functions to create and remove
|
||||
// PID file. A PID file is usually a file used to store the process ID of a
|
||||
// running process.
|
||||
package pid
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// File is a file used to store the process ID of a running process.
|
||||
type File struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func checkPIDFileAlreadyExists(path string) error {
|
||||
if pidByte, err := ioutil.ReadFile(path); err == nil {
|
||||
pidString := strings.TrimSpace(string(pidByte))
|
||||
if pid, err := strconv.Atoi(pidString); err == nil {
|
||||
if processExists(pid) {
|
||||
return fmt.Errorf("pid file found, ensure server is not running or delete %s", path)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// New creates a PID file using the specified path.
|
||||
func New(path string) (*File, error) {
|
||||
if err := checkPIDFileAlreadyExists(path); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := ioutil.WriteFile(path, []byte(fmt.Sprintf("%d", os.Getpid())), 0644); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &File{path: path}, nil
|
||||
}
|
||||
|
||||
// Remove removes the File.
|
||||
func (file File) Remove() error {
|
||||
if err := os.Remove(file.path); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
14
vendor/github.com/pengsrc/go-shared/pid/pidfile_darwin.go
generated
vendored
Normal file
14
vendor/github.com/pengsrc/go-shared/pid/pidfile_darwin.go
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
// +build darwin
|
||||
|
||||
package pid
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func processExists(pid int) bool {
|
||||
// OS X does not have a proc filesystem.
|
||||
// Use kill -0 pid to judge if the process exists.
|
||||
err := syscall.Kill(pid, 0)
|
||||
return err == nil
|
||||
}
|
38
vendor/github.com/pengsrc/go-shared/pid/pidfile_test.go
generated
vendored
Normal file
38
vendor/github.com/pengsrc/go-shared/pid/pidfile_test.go
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
package pid
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewAndRemove(t *testing.T) {
|
||||
dir, err := ioutil.TempDir(os.TempDir(), "test-pidfile")
|
||||
if err != nil {
|
||||
t.Fatal("Could not create test directory")
|
||||
}
|
||||
|
||||
path := filepath.Join(dir, "testfile")
|
||||
file, err := New(path)
|
||||
if err != nil {
|
||||
t.Fatal("Could not create test file", err)
|
||||
}
|
||||
|
||||
_, err = New(path)
|
||||
if err == nil {
|
||||
t.Fatal("Test file creation not blocked")
|
||||
}
|
||||
|
||||
if err := file.Remove(); err != nil {
|
||||
t.Fatal("Could not delete created test file")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveInvalidPath(t *testing.T) {
|
||||
file := File{path: filepath.Join("foo", "bar")}
|
||||
|
||||
if err := file.Remove(); err == nil {
|
||||
t.Fatal("Non-existing file doesn't give an error on delete")
|
||||
}
|
||||
}
|
16
vendor/github.com/pengsrc/go-shared/pid/pidfile_unix.go
generated
vendored
Normal file
16
vendor/github.com/pengsrc/go-shared/pid/pidfile_unix.go
generated
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
// +build !windows,!darwin
|
||||
|
||||
package pid
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func processExists(pid int) bool {
|
||||
if _, err := os.Stat(filepath.Join("/proc", strconv.Itoa(pid))); err == nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
23
vendor/github.com/pengsrc/go-shared/pid/pidfile_windows.go
generated
vendored
Normal file
23
vendor/github.com/pengsrc/go-shared/pid/pidfile_windows.go
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
package pid
|
||||
|
||||
import "syscall"
|
||||
|
||||
const (
|
||||
processQueryLimitedInformation = 0x1000
|
||||
|
||||
stillActive = 259
|
||||
)
|
||||
|
||||
func processExists(pid int) bool {
|
||||
h, err := syscall.OpenProcess(processQueryLimitedInformation, false, uint32(pid))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
var c uint32
|
||||
err = syscall.GetExitCodeProcess(h, &c)
|
||||
syscall.Close(h)
|
||||
if err != nil {
|
||||
return c == stillActive
|
||||
}
|
||||
return true
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue