storage.go 743 B

1234567891011121314151617181920212223242526272829
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package lfsutil
  5. import (
  6. "path/filepath"
  7. "strings"
  8. )
  9. // Storage is the storage type of an LFS object.
  10. type Storage string
  11. const (
  12. StorageLocal Storage = "local"
  13. )
  14. // StorageLocalPath returns computed file path for storing object on local file system.
  15. // It returns empty string if given "oid" isn't valid.
  16. func StorageLocalPath(root string, oid OID) string {
  17. if !ValidOID(oid) {
  18. return ""
  19. }
  20. // Valid OID is guaranteed to have second element as hash.
  21. hash := strings.SplitN(string(oid), ":", 2)[1]
  22. return filepath.Join(root, string(hash[0]), string(hash[1]), hash)
  23. }