vfs.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. // Package vfs provides local and remote filesystems support
  2. package vfs
  3. import (
  4. "errors"
  5. "fmt"
  6. "io"
  7. "net/url"
  8. "os"
  9. "path"
  10. "path/filepath"
  11. "runtime"
  12. "strings"
  13. "time"
  14. "github.com/eikenb/pipeat"
  15. "github.com/pkg/sftp"
  16. "github.com/drakkan/sftpgo/kms"
  17. "github.com/drakkan/sftpgo/logger"
  18. "github.com/drakkan/sftpgo/utils"
  19. )
  20. const dirMimeType = "inode/directory"
  21. var (
  22. validAzAccessTier = []string{"", "Archive", "Hot", "Cool"}
  23. // ErrStorageSizeUnavailable is returned if the storage backend does not support getting the size
  24. ErrStorageSizeUnavailable = errors.New("unable to get available size for this storage backend")
  25. // ErrVfsUnsupported defines the error for an unsupported VFS operation
  26. ErrVfsUnsupported = errors.New("not supported")
  27. credentialsDirPath string
  28. sftpFingerprints []string
  29. )
  30. // SetCredentialsDirPath sets the credentials dir path
  31. func SetCredentialsDirPath(credentialsPath string) {
  32. credentialsDirPath = credentialsPath
  33. }
  34. // GetCredentialsDirPath returns the credentials dir path
  35. func GetCredentialsDirPath() string {
  36. return credentialsDirPath
  37. }
  38. // SetSFTPFingerprints sets the SFTP host key fingerprints
  39. func SetSFTPFingerprints(fp []string) {
  40. sftpFingerprints = fp
  41. }
  42. // Fs defines the interface for filesystem backends
  43. type Fs interface {
  44. Name() string
  45. ConnectionID() string
  46. Stat(name string) (os.FileInfo, error)
  47. Lstat(name string) (os.FileInfo, error)
  48. Open(name string, offset int64) (File, *pipeat.PipeReaderAt, func(), error)
  49. Create(name string, flag int) (File, *PipeWriter, func(), error)
  50. Rename(source, target string) error
  51. Remove(name string, isDir bool) error
  52. Mkdir(name string) error
  53. MkdirAll(name string, uid int, gid int) error
  54. Symlink(source, target string) error
  55. Chown(name string, uid int, gid int) error
  56. Chmod(name string, mode os.FileMode) error
  57. Chtimes(name string, atime, mtime time.Time) error
  58. Truncate(name string, size int64) error
  59. ReadDir(dirname string) ([]os.FileInfo, error)
  60. Readlink(name string) (string, error)
  61. IsUploadResumeSupported() bool
  62. IsAtomicUploadSupported() bool
  63. CheckRootPath(username string, uid int, gid int) bool
  64. ResolvePath(sftpPath string) (string, error)
  65. IsNotExist(err error) bool
  66. IsPermission(err error) bool
  67. IsNotSupported(err error) bool
  68. ScanRootDirContents() (int, int64, error)
  69. GetDirSize(dirname string) (int, int64, error)
  70. GetAtomicUploadPath(name string) string
  71. GetRelativePath(name string) string
  72. Walk(root string, walkFn filepath.WalkFunc) error
  73. Join(elem ...string) string
  74. HasVirtualFolders() bool
  75. GetMimeType(name string) (string, error)
  76. GetAvailableDiskSize(dirName string) (*sftp.StatVFS, error)
  77. Close() error
  78. }
  79. // File defines an interface representing a SFTPGo file
  80. type File interface {
  81. io.Reader
  82. io.Writer
  83. io.Closer
  84. io.ReaderAt
  85. io.WriterAt
  86. io.Seeker
  87. Stat() (os.FileInfo, error)
  88. Name() string
  89. Truncate(size int64) error
  90. }
  91. // QuotaCheckResult defines the result for a quota check
  92. type QuotaCheckResult struct {
  93. HasSpace bool
  94. AllowedSize int64
  95. AllowedFiles int
  96. UsedSize int64
  97. UsedFiles int
  98. QuotaSize int64
  99. QuotaFiles int
  100. }
  101. // GetRemainingSize returns the remaining allowed size
  102. func (q *QuotaCheckResult) GetRemainingSize() int64 {
  103. if q.QuotaSize > 0 {
  104. return q.QuotaSize - q.UsedSize
  105. }
  106. return 0
  107. }
  108. // GetRemainingFiles returns the remaining allowed files
  109. func (q *QuotaCheckResult) GetRemainingFiles() int {
  110. if q.QuotaFiles > 0 {
  111. return q.QuotaFiles - q.UsedFiles
  112. }
  113. return 0
  114. }
  115. // S3FsConfig defines the configuration for S3 based filesystem
  116. type S3FsConfig struct {
  117. Bucket string `json:"bucket,omitempty"`
  118. // KeyPrefix is similar to a chroot directory for local filesystem.
  119. // If specified then the SFTP user will only see objects that starts
  120. // with this prefix and so you can restrict access to a specific
  121. // folder. The prefix, if not empty, must not start with "/" and must
  122. // end with "/".
  123. // If empty the whole bucket contents will be available
  124. KeyPrefix string `json:"key_prefix,omitempty"`
  125. Region string `json:"region,omitempty"`
  126. AccessKey string `json:"access_key,omitempty"`
  127. AccessSecret *kms.Secret `json:"access_secret,omitempty"`
  128. Endpoint string `json:"endpoint,omitempty"`
  129. StorageClass string `json:"storage_class,omitempty"`
  130. // The buffer size (in MB) to use for multipart uploads. The minimum allowed part size is 5MB,
  131. // and if this value is set to zero, the default value (5MB) for the AWS SDK will be used.
  132. // The minimum allowed value is 5.
  133. // Please note that if the upload bandwidth between the SFTP client and SFTPGo is greater than
  134. // the upload bandwidth between SFTPGo and S3 then the SFTP client have to wait for the upload
  135. // of the last parts to S3 after it ends the file upload to SFTPGo, and it may time out.
  136. // Keep this in mind if you customize these parameters.
  137. UploadPartSize int64 `json:"upload_part_size,omitempty"`
  138. // How many parts are uploaded in parallel
  139. UploadConcurrency int `json:"upload_concurrency,omitempty"`
  140. }
  141. func (c *S3FsConfig) isEqual(other *S3FsConfig) bool {
  142. if c.Bucket != other.Bucket {
  143. return false
  144. }
  145. if c.KeyPrefix != other.KeyPrefix {
  146. return false
  147. }
  148. if c.Region != other.Region {
  149. return false
  150. }
  151. if c.AccessKey != other.AccessKey {
  152. return false
  153. }
  154. if c.Endpoint != other.Endpoint {
  155. return false
  156. }
  157. if c.StorageClass != other.StorageClass {
  158. return false
  159. }
  160. if c.UploadPartSize != other.UploadPartSize {
  161. return false
  162. }
  163. if c.UploadConcurrency != other.UploadConcurrency {
  164. return false
  165. }
  166. if c.AccessSecret == nil {
  167. c.AccessSecret = kms.NewEmptySecret()
  168. }
  169. if other.AccessSecret == nil {
  170. other.AccessSecret = kms.NewEmptySecret()
  171. }
  172. return c.AccessSecret.IsEqual(other.AccessSecret)
  173. }
  174. func (c *S3FsConfig) checkCredentials() error {
  175. if c.AccessKey == "" && !c.AccessSecret.IsEmpty() {
  176. return errors.New("access_key cannot be empty with access_secret not empty")
  177. }
  178. if c.AccessSecret.IsEmpty() && c.AccessKey != "" {
  179. return errors.New("access_secret cannot be empty with access_key not empty")
  180. }
  181. if c.AccessSecret.IsEncrypted() && !c.AccessSecret.IsValid() {
  182. return errors.New("invalid encrypted access_secret")
  183. }
  184. if !c.AccessSecret.IsEmpty() && !c.AccessSecret.IsValidInput() {
  185. return errors.New("invalid access_secret")
  186. }
  187. return nil
  188. }
  189. // EncryptCredentials encrypts access secret if it is in plain text
  190. func (c *S3FsConfig) EncryptCredentials(additionalData string) error {
  191. if c.AccessSecret.IsPlain() {
  192. c.AccessSecret.SetAdditionalData(additionalData)
  193. err := c.AccessSecret.Encrypt()
  194. if err != nil {
  195. return err
  196. }
  197. }
  198. return nil
  199. }
  200. // Validate returns an error if the configuration is not valid
  201. func (c *S3FsConfig) Validate() error {
  202. if c.AccessSecret == nil {
  203. c.AccessSecret = kms.NewEmptySecret()
  204. }
  205. if c.Bucket == "" {
  206. return errors.New("bucket cannot be empty")
  207. }
  208. if c.Region == "" {
  209. return errors.New("region cannot be empty")
  210. }
  211. if err := c.checkCredentials(); err != nil {
  212. return err
  213. }
  214. if c.KeyPrefix != "" {
  215. if strings.HasPrefix(c.KeyPrefix, "/") {
  216. return errors.New("key_prefix cannot start with /")
  217. }
  218. c.KeyPrefix = path.Clean(c.KeyPrefix)
  219. if !strings.HasSuffix(c.KeyPrefix, "/") {
  220. c.KeyPrefix += "/"
  221. }
  222. }
  223. if c.UploadPartSize != 0 && (c.UploadPartSize < 5 || c.UploadPartSize > 5000) {
  224. return errors.New("upload_part_size cannot be != 0, lower than 5 (MB) or greater than 5000 (MB)")
  225. }
  226. if c.UploadConcurrency < 0 || c.UploadConcurrency > 64 {
  227. return fmt.Errorf("invalid upload concurrency: %v", c.UploadConcurrency)
  228. }
  229. return nil
  230. }
  231. // GCSFsConfig defines the configuration for Google Cloud Storage based filesystem
  232. type GCSFsConfig struct {
  233. Bucket string `json:"bucket,omitempty"`
  234. // KeyPrefix is similar to a chroot directory for local filesystem.
  235. // If specified then the SFTP user will only see objects that starts
  236. // with this prefix and so you can restrict access to a specific
  237. // folder. The prefix, if not empty, must not start with "/" and must
  238. // end with "/".
  239. // If empty the whole bucket contents will be available
  240. KeyPrefix string `json:"key_prefix,omitempty"`
  241. CredentialFile string `json:"-"`
  242. Credentials *kms.Secret `json:"credentials,omitempty"`
  243. // 0 explicit, 1 automatic
  244. AutomaticCredentials int `json:"automatic_credentials,omitempty"`
  245. StorageClass string `json:"storage_class,omitempty"`
  246. }
  247. func (c *GCSFsConfig) isEqual(other *GCSFsConfig) bool {
  248. if c.Bucket != other.Bucket {
  249. return false
  250. }
  251. if c.KeyPrefix != other.KeyPrefix {
  252. return false
  253. }
  254. if c.AutomaticCredentials != other.AutomaticCredentials {
  255. return false
  256. }
  257. if c.StorageClass != other.StorageClass {
  258. return false
  259. }
  260. if c.Credentials == nil {
  261. c.Credentials = kms.NewEmptySecret()
  262. }
  263. if other.Credentials == nil {
  264. other.Credentials = kms.NewEmptySecret()
  265. }
  266. return c.Credentials.IsEqual(other.Credentials)
  267. }
  268. // Validate returns an error if the configuration is not valid
  269. func (c *GCSFsConfig) Validate(credentialsFilePath string) error {
  270. if c.Credentials == nil {
  271. c.Credentials = kms.NewEmptySecret()
  272. }
  273. if c.Bucket == "" {
  274. return errors.New("bucket cannot be empty")
  275. }
  276. if c.KeyPrefix != "" {
  277. if strings.HasPrefix(c.KeyPrefix, "/") {
  278. return errors.New("key_prefix cannot start with /")
  279. }
  280. c.KeyPrefix = path.Clean(c.KeyPrefix)
  281. if !strings.HasSuffix(c.KeyPrefix, "/") {
  282. c.KeyPrefix += "/"
  283. }
  284. }
  285. if c.Credentials.IsEncrypted() && !c.Credentials.IsValid() {
  286. return errors.New("invalid encrypted credentials")
  287. }
  288. if !c.Credentials.IsValidInput() && c.AutomaticCredentials == 0 {
  289. fi, err := os.Stat(credentialsFilePath)
  290. if err != nil {
  291. return fmt.Errorf("invalid credentials %v", err)
  292. }
  293. if fi.Size() == 0 {
  294. return errors.New("credentials cannot be empty")
  295. }
  296. }
  297. return nil
  298. }
  299. // AzBlobFsConfig defines the configuration for Azure Blob Storage based filesystem
  300. type AzBlobFsConfig struct {
  301. Container string `json:"container,omitempty"`
  302. // Storage Account Name, leave blank to use SAS URL
  303. AccountName string `json:"account_name,omitempty"`
  304. // Storage Account Key leave blank to use SAS URL.
  305. // The access key is stored encrypted based on the kms configuration
  306. AccountKey *kms.Secret `json:"account_key,omitempty"`
  307. // Optional endpoint. Default is "blob.core.windows.net".
  308. // If you use the emulator the endpoint must include the protocol,
  309. // for example "http://127.0.0.1:10000"
  310. Endpoint string `json:"endpoint,omitempty"`
  311. // Shared access signature URL, leave blank if using account/key
  312. SASURL string `json:"sas_url,omitempty"`
  313. // KeyPrefix is similar to a chroot directory for local filesystem.
  314. // If specified then the SFTPGo userd will only see objects that starts
  315. // with this prefix and so you can restrict access to a specific
  316. // folder. The prefix, if not empty, must not start with "/" and must
  317. // end with "/".
  318. // If empty the whole bucket contents will be available
  319. KeyPrefix string `json:"key_prefix,omitempty"`
  320. // The buffer size (in MB) to use for multipart uploads.
  321. // If this value is set to zero, the default value (1MB) for the Azure SDK will be used.
  322. // Please note that if the upload bandwidth between the SFTPGo client and SFTPGo server is
  323. // greater than the upload bandwidth between SFTPGo and Azure then the SFTP client have
  324. // to wait for the upload of the last parts to Azure after it ends the file upload to SFTPGo,
  325. // and it may time out.
  326. // Keep this in mind if you customize these parameters.
  327. UploadPartSize int64 `json:"upload_part_size,omitempty"`
  328. // How many parts are uploaded in parallel
  329. UploadConcurrency int `json:"upload_concurrency,omitempty"`
  330. // Set to true if you use an Azure emulator such as Azurite
  331. UseEmulator bool `json:"use_emulator,omitempty"`
  332. // Blob Access Tier
  333. AccessTier string `json:"access_tier,omitempty"`
  334. }
  335. func (c *AzBlobFsConfig) isEqual(other *AzBlobFsConfig) bool {
  336. if c.Container != other.Container {
  337. return false
  338. }
  339. if c.AccountName != other.AccountName {
  340. return false
  341. }
  342. if c.Endpoint != other.Endpoint {
  343. return false
  344. }
  345. if c.SASURL != other.SASURL {
  346. return false
  347. }
  348. if c.KeyPrefix != other.KeyPrefix {
  349. return false
  350. }
  351. if c.UploadPartSize != other.UploadPartSize {
  352. return false
  353. }
  354. if c.UploadConcurrency != other.UploadConcurrency {
  355. return false
  356. }
  357. if c.UseEmulator != other.UseEmulator {
  358. return false
  359. }
  360. if c.AccessTier != other.AccessTier {
  361. return false
  362. }
  363. if c.AccountKey == nil {
  364. c.AccountKey = kms.NewEmptySecret()
  365. }
  366. if other.AccountKey == nil {
  367. other.AccountKey = kms.NewEmptySecret()
  368. }
  369. return c.AccountKey.IsEqual(other.AccountKey)
  370. }
  371. // EncryptCredentials encrypts access secret if it is in plain text
  372. func (c *AzBlobFsConfig) EncryptCredentials(additionalData string) error {
  373. if c.AccountKey.IsPlain() {
  374. c.AccountKey.SetAdditionalData(additionalData)
  375. if err := c.AccountKey.Encrypt(); err != nil {
  376. return err
  377. }
  378. }
  379. return nil
  380. }
  381. func (c *AzBlobFsConfig) checkCredentials() error {
  382. if c.AccountName == "" || !c.AccountKey.IsValidInput() {
  383. return errors.New("credentials cannot be empty or invalid")
  384. }
  385. if c.AccountKey.IsEncrypted() && !c.AccountKey.IsValid() {
  386. return errors.New("invalid encrypted account_key")
  387. }
  388. return nil
  389. }
  390. // Validate returns an error if the configuration is not valid
  391. func (c *AzBlobFsConfig) Validate() error {
  392. if c.AccountKey == nil {
  393. c.AccountKey = kms.NewEmptySecret()
  394. }
  395. if c.SASURL != "" {
  396. _, err := url.Parse(c.SASURL)
  397. return err
  398. }
  399. if c.Container == "" {
  400. return errors.New("container cannot be empty")
  401. }
  402. if err := c.checkCredentials(); err != nil {
  403. return err
  404. }
  405. if c.KeyPrefix != "" {
  406. if strings.HasPrefix(c.KeyPrefix, "/") {
  407. return errors.New("key_prefix cannot start with /")
  408. }
  409. c.KeyPrefix = path.Clean(c.KeyPrefix)
  410. if !strings.HasSuffix(c.KeyPrefix, "/") {
  411. c.KeyPrefix += "/"
  412. }
  413. }
  414. if c.UploadPartSize < 0 || c.UploadPartSize > 100 {
  415. return fmt.Errorf("invalid upload part size: %v", c.UploadPartSize)
  416. }
  417. if c.UploadConcurrency < 0 || c.UploadConcurrency > 64 {
  418. return fmt.Errorf("invalid upload concurrency: %v", c.UploadConcurrency)
  419. }
  420. if !utils.IsStringInSlice(c.AccessTier, validAzAccessTier) {
  421. return fmt.Errorf("invalid access tier %#v, valid values: \"''%v\"", c.AccessTier, strings.Join(validAzAccessTier, ", "))
  422. }
  423. return nil
  424. }
  425. // CryptFsConfig defines the configuration to store local files as encrypted
  426. type CryptFsConfig struct {
  427. Passphrase *kms.Secret `json:"passphrase,omitempty"`
  428. }
  429. func (c *CryptFsConfig) isEqual(other *CryptFsConfig) bool {
  430. if c.Passphrase == nil {
  431. c.Passphrase = kms.NewEmptySecret()
  432. }
  433. if other.Passphrase == nil {
  434. other.Passphrase = kms.NewEmptySecret()
  435. }
  436. return c.Passphrase.IsEqual(other.Passphrase)
  437. }
  438. // EncryptCredentials encrypts access secret if it is in plain text
  439. func (c *CryptFsConfig) EncryptCredentials(additionalData string) error {
  440. if c.Passphrase.IsPlain() {
  441. c.Passphrase.SetAdditionalData(additionalData)
  442. if err := c.Passphrase.Encrypt(); err != nil {
  443. return err
  444. }
  445. }
  446. return nil
  447. }
  448. // Validate returns an error if the configuration is not valid
  449. func (c *CryptFsConfig) Validate() error {
  450. if c.Passphrase == nil || c.Passphrase.IsEmpty() {
  451. return errors.New("invalid passphrase")
  452. }
  453. if !c.Passphrase.IsValidInput() {
  454. return errors.New("passphrase cannot be empty or invalid")
  455. }
  456. if c.Passphrase.IsEncrypted() && !c.Passphrase.IsValid() {
  457. return errors.New("invalid encrypted passphrase")
  458. }
  459. return nil
  460. }
  461. // PipeWriter defines a wrapper for pipeat.PipeWriterAt.
  462. type PipeWriter struct {
  463. writer *pipeat.PipeWriterAt
  464. err error
  465. done chan bool
  466. }
  467. // NewPipeWriter initializes a new PipeWriter
  468. func NewPipeWriter(w *pipeat.PipeWriterAt) *PipeWriter {
  469. return &PipeWriter{
  470. writer: w,
  471. err: nil,
  472. done: make(chan bool),
  473. }
  474. }
  475. // Close waits for the upload to end, closes the pipeat.PipeWriterAt and returns an error if any.
  476. func (p *PipeWriter) Close() error {
  477. p.writer.Close() //nolint:errcheck // the returned error is always null
  478. <-p.done
  479. return p.err
  480. }
  481. // Done unlocks other goroutines waiting on Close().
  482. // It must be called when the upload ends
  483. func (p *PipeWriter) Done(err error) {
  484. p.err = err
  485. p.done <- true
  486. }
  487. // WriteAt is a wrapper for pipeat WriteAt
  488. func (p *PipeWriter) WriteAt(data []byte, off int64) (int, error) {
  489. return p.writer.WriteAt(data, off)
  490. }
  491. // Write is a wrapper for pipeat Write
  492. func (p *PipeWriter) Write(data []byte) (int, error) {
  493. return p.writer.Write(data)
  494. }
  495. // IsDirectory checks if a path exists and is a directory
  496. func IsDirectory(fs Fs, path string) (bool, error) {
  497. fileInfo, err := fs.Stat(path)
  498. if err != nil {
  499. return false, err
  500. }
  501. return fileInfo.IsDir(), err
  502. }
  503. // IsLocalOsFs returns true if fs is a local filesystem implementation
  504. func IsLocalOsFs(fs Fs) bool {
  505. return fs.Name() == osFsName
  506. }
  507. // IsCryptOsFs returns true if fs is an encrypted local filesystem implementation
  508. func IsCryptOsFs(fs Fs) bool {
  509. return fs.Name() == cryptFsName
  510. }
  511. // IsSFTPFs returns true if fs is an SFTP filesystem
  512. func IsSFTPFs(fs Fs) bool {
  513. return strings.HasPrefix(fs.Name(), sftpFsName)
  514. }
  515. // IsBufferedSFTPFs returns true if this is a buffered SFTP filesystem
  516. func IsBufferedSFTPFs(fs Fs) bool {
  517. if !IsSFTPFs(fs) {
  518. return false
  519. }
  520. return !fs.IsUploadResumeSupported()
  521. }
  522. // IsLocalOrUnbufferedSFTPFs returns true if fs is local or SFTP with no buffer
  523. func IsLocalOrUnbufferedSFTPFs(fs Fs) bool {
  524. if IsLocalOsFs(fs) {
  525. return true
  526. }
  527. if IsSFTPFs(fs) {
  528. return fs.IsUploadResumeSupported()
  529. }
  530. return false
  531. }
  532. // IsLocalOrSFTPFs returns true if fs is local or SFTP
  533. func IsLocalOrSFTPFs(fs Fs) bool {
  534. return IsLocalOsFs(fs) || IsSFTPFs(fs)
  535. }
  536. // HasOpenRWSupport returns true if the fs can open a file
  537. // for reading and writing at the same time
  538. func HasOpenRWSupport(fs Fs) bool {
  539. if IsLocalOsFs(fs) {
  540. return true
  541. }
  542. if IsSFTPFs(fs) && fs.IsUploadResumeSupported() {
  543. return true
  544. }
  545. return false
  546. }
  547. // IsLocalOrCryptoFs returns true if fs is local or local encrypted
  548. func IsLocalOrCryptoFs(fs Fs) bool {
  549. return IsLocalOsFs(fs) || IsCryptOsFs(fs)
  550. }
  551. // SetPathPermissions calls fs.Chown.
  552. // It does nothing for local filesystem on windows
  553. func SetPathPermissions(fs Fs, path string, uid int, gid int) {
  554. if uid == -1 && gid == -1 {
  555. return
  556. }
  557. if IsLocalOsFs(fs) {
  558. if runtime.GOOS == "windows" {
  559. return
  560. }
  561. }
  562. if err := fs.Chown(path, uid, gid); err != nil {
  563. fsLog(fs, logger.LevelWarn, "error chowning path %v: %v", path, err)
  564. }
  565. }
  566. func fsLog(fs Fs, level logger.LogLevel, format string, v ...interface{}) {
  567. logger.Log(level, fs.Name(), fs.ConnectionID(), format, v...)
  568. }