lock_windows.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // +build windows
  15. package fileutil
  16. import (
  17. "errors"
  18. "os"
  19. )
  20. var (
  21. ErrLocked = errors.New("file already locked")
  22. )
  23. type lock struct {
  24. fd int
  25. file *os.File
  26. }
  27. func (l *lock) Name() string {
  28. return l.file.Name()
  29. }
  30. func (l *lock) TryLock() error {
  31. return nil
  32. }
  33. func (l *lock) Lock() error {
  34. return nil
  35. }
  36. func (l *lock) Unlock() error {
  37. return nil
  38. }
  39. func (l *lock) Destroy() error {
  40. return l.file.Close()
  41. }
  42. func NewLock(file string) (Lock, error) {
  43. f, err := os.Open(file)
  44. if err != nil {
  45. return nil, err
  46. }
  47. l := &lock{int(f.Fd()), f}
  48. return l, nil
  49. }