本站源代码
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

102 linhas
2.6KB

  1. // Copyright © 2014 Steve Francia <spf@spf13.com>.
  2. // Copyright 2013 tsuru authors. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  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. package afero
  15. import (
  16. "os"
  17. "time"
  18. )
  19. var _ Lstater = (*OsFs)(nil)
  20. // OsFs is a Fs implementation that uses functions provided by the os package.
  21. //
  22. // For details in any method, check the documentation of the os package
  23. // (http://golang.org/pkg/os/).
  24. type OsFs struct{}
  25. func NewOsFs() Fs {
  26. return &OsFs{}
  27. }
  28. func (OsFs) Name() string { return "OsFs" }
  29. func (OsFs) Create(name string) (File, error) {
  30. f, e := os.Create(name)
  31. if f == nil {
  32. // while this looks strange, we need to return a bare nil (of type nil) not
  33. // a nil value of type *os.File or nil won't be nil
  34. return nil, e
  35. }
  36. return f, e
  37. }
  38. func (OsFs) Mkdir(name string, perm os.FileMode) error {
  39. return os.Mkdir(name, perm)
  40. }
  41. func (OsFs) MkdirAll(path string, perm os.FileMode) error {
  42. return os.MkdirAll(path, perm)
  43. }
  44. func (OsFs) Open(name string) (File, error) {
  45. f, e := os.Open(name)
  46. if f == nil {
  47. // while this looks strange, we need to return a bare nil (of type nil) not
  48. // a nil value of type *os.File or nil won't be nil
  49. return nil, e
  50. }
  51. return f, e
  52. }
  53. func (OsFs) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
  54. f, e := os.OpenFile(name, flag, perm)
  55. if f == nil {
  56. // while this looks strange, we need to return a bare nil (of type nil) not
  57. // a nil value of type *os.File or nil won't be nil
  58. return nil, e
  59. }
  60. return f, e
  61. }
  62. func (OsFs) Remove(name string) error {
  63. return os.Remove(name)
  64. }
  65. func (OsFs) RemoveAll(path string) error {
  66. return os.RemoveAll(path)
  67. }
  68. func (OsFs) Rename(oldname, newname string) error {
  69. return os.Rename(oldname, newname)
  70. }
  71. func (OsFs) Stat(name string) (os.FileInfo, error) {
  72. return os.Stat(name)
  73. }
  74. func (OsFs) Chmod(name string, mode os.FileMode) error {
  75. return os.Chmod(name, mode)
  76. }
  77. func (OsFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
  78. return os.Chtimes(name, atime, mtime)
  79. }
  80. func (OsFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {
  81. fi, err := os.Lstat(name)
  82. return fi, true, err
  83. }
上海开阖软件有限公司 沪ICP备12045867号-1