[server] Move core.fs => core

This commit is contained in:
Abhishek Shroff
2025-06-05 20:50:45 +05:30
parent 6b304a872a
commit 40528a7fee
52 changed files with 182 additions and 182 deletions
@@ -6,8 +6,8 @@ import (
"strings"
"github.com/gin-gonic/gin"
"github.com/shroff/phylum/server/internal/core"
"github.com/shroff/phylum/server/internal/core/errors"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core/user"
)
@@ -24,12 +24,12 @@ func GetUser(c *gin.Context) user.User {
return val.(user.User)
}
func GetFileSystem(c *gin.Context) fs.FileSystem {
func GetFileSystem(c *gin.Context) core.FileSystem {
val, ok := c.Get(keyFileSystem)
if !ok {
return nil
}
return val.(fs.FileSystem)
return val.(core.FileSystem)
}
func Require(c *gin.Context) {
+5 -5
View File
@@ -6,7 +6,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/shroff/phylum/server/internal/api/serve"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
)
func Setup(r *gin.RouterGroup) {
@@ -15,18 +15,18 @@ func Setup(r *gin.RouterGroup) {
path := c.Param("path")
_, password, _ := c.Request.BasicAuth()
f, err := fs.OpenFromPublink(c.Request.Context(), id, password)
f, err := core.OpenFromPublink(c.Request.Context(), id, password)
if err != nil {
if errors.Is(err, fs.ErrInsufficientPermissions) {
if errors.Is(err, core.ErrInsufficientPermissions) {
c.Header("WWW-Authenticate", "Basic realm=\""+id+"\"")
c.AbortWithStatus(http.StatusUnauthorized)
} else if errors.Is(err, fs.ErrResourceNotFound) {
} else if errors.Is(err, core.ErrResourceNotFound) {
c.AbortWithStatus(http.StatusNotFound)
} else {
c.AbortWithStatus(http.StatusInternalServerError)
}
} else if r, err := f.ResourceByPath(path); err != nil {
if errors.Is(err, fs.ErrResourceNotFound) {
if errors.Is(err, core.ErrResourceNotFound) {
c.AbortWithStatus(http.StatusNotFound)
} else {
c.AbortWithStatus(http.StatusInternalServerError)
+12 -12
View File
@@ -13,7 +13,7 @@ import (
"time"
"github.com/google/uuid"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
"github.com/shroff/phylum/server/internal/core/storage"
)
@@ -28,11 +28,11 @@ var htmlReplacer = strings.NewReplacer(
)
type FileSystem interface {
ReadDir(fs.Resource, bool) ([]fs.Resource, error)
FindVersion(fs.Resource, uuid.UUID) (fs.Version, error)
ReadDir(core.Resource, bool) ([]core.Resource, error)
FindVersion(core.Resource, uuid.UUID) (core.Version, error)
}
func Serve(w http.ResponseWriter, r *http.Request, f FileSystem, res fs.Resource) {
func Serve(w http.ResponseWriter, r *http.Request, f FileSystem, res core.Resource) {
if res.Dir() {
serveCollection(w, r, f, res)
} else {
@@ -40,7 +40,7 @@ func Serve(w http.ResponseWriter, r *http.Request, f FileSystem, res fs.Resource
}
}
func serveCollection(w http.ResponseWriter, r *http.Request, f FileSystem, file fs.Resource) {
func serveCollection(w http.ResponseWriter, r *http.Request, f FileSystem, file core.Resource) {
if !strings.HasSuffix(r.URL.Path, "/") {
http.Redirect(w, r, r.URL.String()+"/", http.StatusMovedPermanently)
return
@@ -110,7 +110,7 @@ func formatSize(size int) string {
return fmt.Sprintf("%d%s", size, suffix[si])
}
func ServeResourceVersion(w http.ResponseWriter, r *http.Request, f FileSystem, res fs.Resource, versionID uuid.UUID) {
func ServeResourceVersion(w http.ResponseWriter, r *http.Request, f FileSystem, res core.Resource, versionID uuid.UUID) {
if versionID == uuid.Nil {
versionID = res.LatestVersion().ID
}
@@ -269,7 +269,7 @@ func parseRange(s string, size int) ([]httpRange, error) {
// checkPreconditions evaluates request preconditions and reports whether a precondition
// resulted in sending StatusNotModified or StatusPreconditionFailed.
func checkPreconditions(w http.ResponseWriter, r *http.Request, v fs.VersionInfo) (done bool, rangeHeader string) {
func checkPreconditions(w http.ResponseWriter, r *http.Request, v core.VersionInfo) (done bool, rangeHeader string) {
// This function carefully follows RFC 7232 section 6.
ch := checkIfMatch(r, v)
if ch == condNone {
@@ -352,7 +352,7 @@ const (
condFalse
)
func checkIfMatch(r *http.Request, v fs.VersionInfo) condResult {
func checkIfMatch(r *http.Request, v core.VersionInfo) condResult {
im := r.Header.Get("If-Match")
if im == "" {
return condNone
@@ -382,7 +382,7 @@ func checkIfMatch(r *http.Request, v fs.VersionInfo) condResult {
return condFalse
}
func checkIfUnmodifiedSince(r *http.Request, v fs.VersionInfo) condResult {
func checkIfUnmodifiedSince(r *http.Request, v core.VersionInfo) condResult {
ius := r.Header.Get("If-Unmodified-Since")
if ius == "" {
return condNone
@@ -400,7 +400,7 @@ func checkIfUnmodifiedSince(r *http.Request, v fs.VersionInfo) condResult {
return condFalse
}
func checkIfNoneMatch(r *http.Request, v fs.VersionInfo) condResult {
func checkIfNoneMatch(r *http.Request, v core.VersionInfo) condResult {
inm := r.Header.Get("If-None-Match")
if inm == "" {
return condNone
@@ -430,7 +430,7 @@ func checkIfNoneMatch(r *http.Request, v fs.VersionInfo) condResult {
return condTrue
}
func checkIfModifiedSince(r *http.Request, v fs.VersionInfo) condResult {
func checkIfModifiedSince(r *http.Request, v core.VersionInfo) condResult {
if r.Method != "GET" && r.Method != "HEAD" {
return condNone
}
@@ -450,7 +450,7 @@ func checkIfModifiedSince(r *http.Request, v fs.VersionInfo) condResult {
return condTrue
}
func checkIfRange(r *http.Request, v fs.VersionInfo) condResult {
func checkIfRange(r *http.Request, v core.VersionInfo) condResult {
if r.Method != "GET" && r.Method != "HEAD" {
return condNone
}
+2 -2
View File
@@ -9,8 +9,8 @@ import (
"github.com/google/uuid"
"github.com/shroff/phylum/server/internal/api/authenticator"
"github.com/shroff/phylum/server/internal/api/serve"
"github.com/shroff/phylum/server/internal/core"
"github.com/shroff/phylum/server/internal/core/errors"
"github.com/shroff/phylum/server/internal/core/fs"
)
var errGetCollectionContents = errors.NewError(http.StatusBadRequest, "resource_is_collection", "Cannot get contents of collection")
@@ -61,7 +61,7 @@ func handleContentsRequest(c *gin.Context) {
var zip = zip.NewWriter(c.Writer)
close := c.Writer.CloseNotify()
err = f.Walk(r, 2, func(r fs.Resource, p string) error {
err = f.Walk(r, 2, func(r core.Resource, p string) error {
if r.Dir() {
return nil
}
+6 -6
View File
@@ -5,15 +5,15 @@ import (
"github.com/google/uuid"
"github.com/shroff/phylum/server/internal/api/authenticator"
"github.com/shroff/phylum/server/internal/api/v1/responses"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
)
type copyParams struct {
Src string `json:"src" form:"src" binding:"required"`
Dest string `json:"dest" form:"dest" binding:"required"`
ID uuid.UUID `json:"id" form:"id"`
VersionID uuid.UUID `json:"version_id" form:"id"`
Conflict fs.ResourceBindConflictResolution `json:"conflict" form:"conflict"`
Src string `json:"src" form:"src" binding:"required"`
Dest string `json:"dest" form:"dest" binding:"required"`
ID uuid.UUID `json:"id" form:"id"`
VersionID uuid.UUID `json:"version_id" form:"id"`
Conflict core.ResourceBindConflictResolution `json:"conflict" form:"conflict"`
}
func handleCopyRequest(c *gin.Context) {
+5 -5
View File
@@ -5,14 +5,14 @@ import (
"github.com/google/uuid"
"github.com/shroff/phylum/server/internal/api/authenticator"
"github.com/shroff/phylum/server/internal/api/v1/responses"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
)
type mkdirParams struct {
Path string `json:"path" form:"path" binding:"required"`
CreateParents bool `json:"create_parents" form:"create_parents"`
ID uuid.UUID `json:"id" form:"id"`
Conflict fs.ResourceBindConflictResolution `json:"conflict" form:"conflict"`
Path string `json:"path" form:"path" binding:"required"`
CreateParents bool `json:"create_parents" form:"create_parents"`
ID uuid.UUID `json:"id" form:"id"`
Conflict core.ResourceBindConflictResolution `json:"conflict" form:"conflict"`
}
func handleMkdirRequest(c *gin.Context) {
+4 -4
View File
@@ -4,13 +4,13 @@ import (
"github.com/gin-gonic/gin"
"github.com/shroff/phylum/server/internal/api/authenticator"
"github.com/shroff/phylum/server/internal/api/v1/responses"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
)
type moveParams struct {
Src string `json:"src" form:"src" binding:"required"`
Dest string `json:"dest" form:"dest" binding:"required"`
Conflict fs.ResourceBindConflictResolution `json:"conflict" form:"conflict"`
Src string `json:"src" form:"src" binding:"required"`
Dest string `json:"dest" form:"dest" binding:"required"`
Conflict core.ResourceBindConflictResolution `json:"conflict" form:"conflict"`
}
func handleMoveRequest(c *gin.Context) {
+4 -4
View File
@@ -4,14 +4,14 @@ import (
"github.com/gin-gonic/gin"
"github.com/shroff/phylum/server/internal/api/authenticator"
"github.com/shroff/phylum/server/internal/api/v1/responses"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
"github.com/shroff/phylum/server/internal/core/user"
)
type shareParams struct {
Path string `json:"path" form:"path" binding:"required"`
Email string `json:"email" form:"email" binding:"required"`
Permission fs.Permission `json:"permission" form:"permission"`
Path string `json:"path" form:"path" binding:"required"`
Email string `json:"email" form:"email" binding:"required"`
Permission core.Permission `json:"permission" form:"permission"`
}
func handleShareRequest(c *gin.Context) {
+8 -8
View File
@@ -8,16 +8,16 @@ import (
"github.com/google/uuid"
"github.com/shroff/phylum/server/internal/api/authenticator"
"github.com/shroff/phylum/server/internal/api/v1/responses"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
)
type uploadParams struct {
Path string `json:"path" form:"path" binding:"required"`
ID string `json:"id" form:"id" binding:"omitempty,uuid"`
VersionID string `json:"version_id" form:"version_id" binding:"omitempty,uuid"`
CreateParents bool `json:"create_parents" form:"create_parents"`
Conflict fs.ResourceBindConflictResolution `json:"conflict" form:"conflict"`
SHA256 string `json:"sha256" form:"sha256"`
Path string `json:"path" form:"path" binding:"required"`
ID string `json:"id" form:"id" binding:"omitempty,uuid"`
VersionID string `json:"version_id" form:"version_id" binding:"omitempty,uuid"`
CreateParents bool `json:"create_parents" form:"create_parents"`
Conflict core.ResourceBindConflictResolution `json:"conflict" form:"conflict"`
SHA256 string `json:"sha256" form:"sha256"`
}
func handleUploadRequest(c *gin.Context) {
@@ -44,7 +44,7 @@ func handleUploadRequest(c *gin.Context) {
// TODO: Calculate and verify sha sum
f := authenticator.GetFileSystem(c)
err = f.RunInTx(func(f fs.FileSystem) error {
err = f.RunInTx(func(f core.FileSystem) error {
res, err := f.CreateResourceByPath(params.Path, id, false, params.CreateParents, params.Conflict)
if err != nil {
return err
+4 -4
View File
@@ -1,8 +1,8 @@
package responses
import "github.com/shroff/phylum/server/internal/core/fs"
import "github.com/shroff/phylum/server/internal/core"
func FullResourceFromFS(f fs.FileSystem, r fs.Resource) ResourceFull {
func FullResourceFromFS(f core.FileSystem, r core.Resource) ResourceFull {
response := ResourceFull{
Resource: ResourceFromFS(r),
}
@@ -32,7 +32,7 @@ func FullResourceFromFS(f fs.FileSystem, r fs.Resource) ResourceFull {
return response
}
func ResourceFromFS(r fs.Resource) Resource {
func ResourceFromFS(r core.Resource) Resource {
var deleted int64 = 0
if r.Deleted().Valid {
deleted = r.Deleted().Time.UnixMilli()
@@ -52,7 +52,7 @@ func ResourceFromFS(r fs.Resource) Resource {
}
}
func PublinkFromFS(p fs.Publink) Publink {
func PublinkFromFS(p core.Publink) Publink {
return Publink{
ID: p.ID,
Created: p.Created,
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
webdav "github.com/shroff/phylum/server/internal/api/webdav/impl"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
"github.com/shroff/phylum/server/internal/core/user"
"github.com/sirupsen/logrus"
)
@@ -41,7 +41,7 @@ func SetupHandler(r *gin.RouterGroup) {
func (h *handler) HandleRequest(c *gin.Context) {
authSuccess := false
var f fs.FileSystem
var f core.FileSystem
if email, pass, ok := c.Request.BasicAuth(); ok {
ctx := c.Request.Context()
userManager := user.ManagerFromContext(ctx)
+5 -5
View File
@@ -5,8 +5,8 @@ import (
"net/url"
"github.com/google/uuid"
"github.com/shroff/phylum/server/internal/core"
"github.com/shroff/phylum/server/internal/core/errors"
"github.com/shroff/phylum/server/internal/core/fs"
)
func (h *Handler) handleCopyMove(_ http.ResponseWriter, r *http.Request) (status int, err error) {
@@ -91,9 +91,9 @@ func moveFiles(f FileSystem, srcPath, dstPath string, overwrite bool) (status in
}
return http.StatusInternalServerError, err
} else {
var conflictResolution fs.ResourceBindConflictResolution = fs.ResourceBindConflictResolutionError
var conflictResolution core.ResourceBindConflictResolution = core.ResourceBindConflictResolutionError
if overwrite {
conflictResolution = fs.ResourceBindConflictResolutionDelete
conflictResolution = core.ResourceBindConflictResolutionDelete
}
if _, deleted, err := f.Move(src, dstPath, conflictResolution); err != nil {
if e, ok := err.(*errors.Error); ok {
@@ -121,9 +121,9 @@ func copyFiles(f FileSystem, srcPath, dstPath string, overwrite bool, depth int)
return http.StatusInternalServerError, err
} else {
id, _ := uuid.NewV7()
var conflictResolution fs.ResourceBindConflictResolution = fs.ResourceBindConflictResolutionError
var conflictResolution core.ResourceBindConflictResolution = core.ResourceBindConflictResolutionError
if overwrite {
conflictResolution = fs.ResourceBindConflictResolutionOverwrite
conflictResolution = core.ResourceBindConflictResolutionOverwrite
}
if _, deleted, err := f.Copy(src, dstPath, id, depth != 0, conflictResolution); err != nil {
if e, ok := err.(*errors.Error); ok {
+13 -13
View File
@@ -10,7 +10,7 @@ import (
"net/http"
"strconv"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
)
// Proppatch describes a property update instruction as defined in RFC 4918.
@@ -69,7 +69,7 @@ func makePropstats(x, y Propstat) []Propstat {
var liveProps = map[xml.Name]struct {
// findFn implements the propfind function of this property. If nil,
// it indicates a hidden property.
findFn func(fs.Resource) string
findFn func(core.Resource) string
// dir is true if the property applies to directories.
dir bool
}{
@@ -132,7 +132,7 @@ var liveProps = map[xml.Name]struct {
//
// Each Propstat has a unique status and each property name will only be part
// of one Propstat element.
func props(fs FileSystem, ls LockSystem, fi fs.Resource, pnames []xml.Name) ([]Propstat, error) {
func props(fs FileSystem, ls LockSystem, fi core.Resource, pnames []xml.Name) ([]Propstat, error) {
pstatOK := Propstat{Status: http.StatusOK}
pstatNotFound := Propstat{Status: http.StatusNotFound}
for _, pn := range pnames {
@@ -153,7 +153,7 @@ func props(fs FileSystem, ls LockSystem, fi fs.Resource, pnames []xml.Name) ([]P
}
// propnames returns the property names defined for resource name.
func propnames(fs FileSystem, ls LockSystem, fi fs.Resource) ([]xml.Name, error) {
func propnames(fs FileSystem, ls LockSystem, fi core.Resource) ([]xml.Name, error) {
pnames := make([]xml.Name, 0, len(liveProps))
for pn, prop := range liveProps {
if prop.findFn != nil && (prop.dir || !fi.Dir()) {
@@ -171,7 +171,7 @@ func propnames(fs FileSystem, ls LockSystem, fi fs.Resource) ([]xml.Name, error)
// returned if they are named in 'include'.
//
// See http://www.webdav.org/specs/rfc4918.html#METHOD_PROPFIND
func allprop(fs FileSystem, ls LockSystem, fi fs.Resource, include []xml.Name) ([]Propstat, error) {
func allprop(fs FileSystem, ls LockSystem, fi core.Resource, include []xml.Name) ([]Propstat, error) {
pnames, err := propnames(fs, ls, fi)
if err != nil {
return nil, err
@@ -252,38 +252,38 @@ func escapeXML(s string) string {
return s
}
func findResourceType(fi fs.Resource) string {
func findResourceType(fi core.Resource) string {
if fi.Dir() {
return `<D:collection xmlns:D="DAV:"/>`
}
return ""
}
func findDisplayName(fi fs.Resource) string {
func findDisplayName(fi core.Resource) string {
return escapeXML(fi.Name())
}
func findContentLength(fi fs.Resource) string {
func findContentLength(fi core.Resource) string {
return strconv.Itoa(int(fi.LatestVersion().Size))
}
func findCreationDate(fi fs.Resource) string {
func findCreationDate(fi core.Resource) string {
return fi.Created().UTC().Format(http.TimeFormat)
}
func findLastModified(fi fs.Resource) string {
func findLastModified(fi core.Resource) string {
return fi.Modified().UTC().Format(http.TimeFormat)
}
func findContentType(fi fs.Resource) string {
func findContentType(fi core.Resource) string {
return fi.LatestVersion().MimeType
}
func findETag(fi fs.Resource) string {
func findETag(fi core.Resource) string {
return fi.LatestVersion().SHA256
}
func findSupportedLock(fi fs.Resource) string {
func findSupportedLock(fi core.Resource) string {
return `` +
`<D:lockentry xmlns:D="DAV:">` +
`<D:lockscope><D:exclusive/></D:lockscope>` +
+19 -19
View File
@@ -17,7 +17,7 @@ import (
"github.com/google/uuid"
"github.com/shroff/phylum/server/internal/api/serve"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
)
type Handler struct {
@@ -36,13 +36,13 @@ type Handler struct {
// in a file path are separated by slash ('/', U+002F) characters, regardless
// of host operating system convention.
type FileSystem interface {
fs.ROFileSystem
core.ROFileSystem
CreateResourceByPath(name string, id uuid.UUID, dir, recursive bool, conflictResolution fs.ResourceBindConflictResolution) (fs.Resource, error)
OpenWrite(fs.Resource, uuid.UUID) (io.WriteCloser, error)
Copy(fs.Resource, string, uuid.UUID, bool, fs.ResourceBindConflictResolution) (fs.Resource, bool, error)
Move(fs.Resource, string, fs.ResourceBindConflictResolution) (fs.Resource, bool, error)
DeleteRecursive(fs.Resource, bool) (fs.Resource, error)
CreateResourceByPath(name string, id uuid.UUID, dir, recursive bool, conflictResolution core.ResourceBindConflictResolution) (core.Resource, error)
OpenWrite(core.Resource, uuid.UUID) (io.WriteCloser, error)
Copy(core.Resource, string, uuid.UUID, bool, core.ResourceBindConflictResolution) (core.Resource, bool, error)
Move(core.Resource, string, core.ResourceBindConflictResolution) (core.Resource, bool, error)
DeleteRecursive(core.Resource, bool) (core.Resource, error)
}
func (h *Handler) stripPrefix(p string) (string, int, error) {
@@ -242,7 +242,7 @@ func (h *Handler) handleDelete(_ http.ResponseWriter, r *http.Request) (status i
defer release()
if r, err := h.FileSystem.ResourceByPath(reqPath); err != nil {
if errors.Is(err, fs.ErrResourceNotFound) {
if errors.Is(err, core.ErrResourceNotFound) {
return http.StatusNotFound, err
}
return http.StatusMethodNotAllowed, err
@@ -265,12 +265,12 @@ func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request) (status int,
// TODO(rost): Support the If-Match, If-None-Match headers? See bradfitz'
// comments in http.checkEtag.
res, err := h.FileSystem.CreateResourceByPath(reqPath, uuid.Nil, false, false, fs.ResourceBindConflictResolutionEnsure)
res, err := h.FileSystem.CreateResourceByPath(reqPath, uuid.Nil, false, false, core.ResourceBindConflictResolutionEnsure)
if err != nil {
if errors.Is(err, fs.ErrParentNotFound) {
if errors.Is(err, core.ErrParentNotFound) {
return http.StatusConflict, err
} else if errors.Is(err, fs.ErrResourceCollection) {
return http.StatusConflict, fs.ErrResourceCollection
} else if errors.Is(err, core.ErrResourceCollection) {
return http.StatusConflict, core.ErrResourceCollection
}
return http.StatusNotFound, err
}
@@ -306,8 +306,8 @@ func (h *Handler) handleMkcol(_ http.ResponseWriter, r *http.Request) (status in
if r.ContentLength > 0 {
return http.StatusUnsupportedMediaType, nil
}
if _, err := h.FileSystem.CreateResourceByPath(reqPath, uuid.Nil, true, false, fs.ResourceBindConflictResolutionError); err != nil {
if errors.Is(err, fs.ErrParentNotFound) {
if _, err := h.FileSystem.CreateResourceByPath(reqPath, uuid.Nil, true, false, core.ResourceBindConflictResolutionError); err != nil {
if errors.Is(err, core.ErrParentNotFound) {
return http.StatusConflict, err
}
return http.StatusMethodNotAllowed, err
@@ -383,9 +383,9 @@ func (h *Handler) handleLock(w http.ResponseWriter, r *http.Request) (retStatus
// Create the resource if it didn't previously exist.
if _, err := h.FileSystem.ResourceByPath(reqPath); err != nil {
_, err = h.FileSystem.CreateResourceByPath(reqPath, uuid.Nil, false, false, fs.ResourceBindConflictResolutionEnsure)
_, err = h.FileSystem.CreateResourceByPath(reqPath, uuid.Nil, false, false, core.ResourceBindConflictResolutionEnsure)
if err != nil {
if errors.Is(err, fs.ErrParentNotFound) {
if errors.Is(err, core.ErrParentNotFound) {
return http.StatusConflict, err
}
return http.StatusNotFound, err
@@ -439,7 +439,7 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, request *http.Request) (
}
fi, err := h.FileSystem.ResourceByPath(reqPath)
if err != nil {
if errors.Is(err, fs.ErrResourceNotFound) {
if errors.Is(err, core.ErrResourceNotFound) {
return http.StatusNotFound, err
}
return http.StatusMethodNotAllowed, err
@@ -458,7 +458,7 @@ func (h *Handler) handlePropfind(w http.ResponseWriter, request *http.Request) (
mw := multistatusWriter{w: w}
writePropStat := func(r fs.Resource, p string) error {
writePropStat := func(r core.Resource, p string) error {
var pstats []Propstat
if pf.Propname != nil {
pnames, err := propnames(h.FileSystem, h.LockSystem, r)
@@ -508,7 +508,7 @@ func (h *Handler) handleProppatch(w http.ResponseWriter, r *http.Request) (statu
defer release()
if _, err := h.FileSystem.ResourceByPath(reqPath); err != nil {
if errors.Is(err, fs.ErrResourceNotFound) {
if errors.Is(err, core.ErrResourceNotFound) {
return http.StatusNotFound, err
}
return http.StatusMethodNotAllowed, err
+2 -2
View File
@@ -6,8 +6,8 @@ import (
"os"
"github.com/jackc/pgx/v5/pgtype"
"github.com/shroff/phylum/server/internal/core"
"github.com/shroff/phylum/server/internal/core/db"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core/user"
"github.com/spf13/cobra"
)
@@ -27,7 +27,7 @@ func setupModCommand() *cobra.Command {
name, _ := cmd.Flags().GetString("name")
f := fs.OpenOmniscient(db.Get(context.Background()))
f := core.OpenOmniscient(db.Get(context.Background()))
var homeID pgtype.UUID
path, _ := cmd.Flags().GetString("home")
if path != "" {
+4 -4
View File
@@ -5,14 +5,14 @@ import (
"fmt"
"os"
"github.com/shroff/phylum/server/internal/core"
"github.com/shroff/phylum/server/internal/core/db"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core/user"
"github.com/spf13/cobra"
)
var u *user.User
var f fs.FileSystem
var f core.FileSystem
func User(cmd *cobra.Command) *user.User {
if u == nil {
@@ -33,11 +33,11 @@ func User(cmd *cobra.Command) *user.User {
return u
}
func UserFileSystem(cmd *cobra.Command) fs.FileSystem {
func UserFileSystem(cmd *cobra.Command) core.FileSystem {
if f == nil {
user := User(cmd)
if user == nil {
f = fs.OpenOmniscient(db.Get(context.Background()))
f = core.OpenOmniscient(db.Get(context.Background()))
} else {
f = user.OpenFileSystem(context.Background())
}
+10 -10
View File
@@ -6,10 +6,10 @@ import (
"strings"
"github.com/jackc/pgx/v5/pgtype"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
)
func FormatResourceSummary(r fs.Resource, name string, deleted pgtype.Timestamp) string {
func FormatResourceSummary(r core.Resource, name string, deleted pgtype.Timestamp) string {
if name == "" {
name = r.Name()
}
@@ -55,21 +55,21 @@ func formatGrantsJson(j []byte) string {
return "[" + strings.Join(perm, ", ") + "]"
}
func FormatPermission(p fs.Permission) string {
if p == fs.PermissionSU {
func FormatPermission(p core.Permission) string {
if p == core.PermissionSU {
return "su"
}
str := ""
if p&fs.PermissionRead != 0 {
p -= fs.PermissionRead
if p&core.PermissionRead != 0 {
p -= core.PermissionRead
str += "r"
}
if p&fs.PermissionWrite != 0 {
p -= fs.PermissionWrite
if p&core.PermissionWrite != 0 {
p -= core.PermissionWrite
str += "w"
}
if p&fs.PermissionShare != 0 {
p -= fs.PermissionShare
if p&core.PermissionShare != 0 {
p -= core.PermissionShare
str += "s"
}
if p != 0 {
+3 -3
View File
@@ -6,7 +6,7 @@ import (
"github.com/google/uuid"
"github.com/shroff/phylum/server/internal/command/common"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
"github.com/spf13/cobra"
)
@@ -33,9 +33,9 @@ func setupCpCommand() *cobra.Command {
}
id, _ := uuid.NewV7()
var conflictResolution fs.ResourceBindConflictResolution = fs.ResourceBindConflictResolutionError
var conflictResolution core.ResourceBindConflictResolution = core.ResourceBindConflictResolutionError
if force {
conflictResolution = fs.ResourceBindConflictResolutionOverwrite
conflictResolution = core.ResourceBindConflictResolutionOverwrite
}
if _, _, err := f.Copy(src, args[1], id, true, conflictResolution); err != nil {
fmt.Println("cannot copy'" + srcPath + "' to '" + args[1] + "': " + err.Error())
+11 -11
View File
@@ -10,7 +10,7 @@ import (
"github.com/google/uuid"
"github.com/shroff/phylum/server/internal/command/common"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
"github.com/spf13/cobra"
)
@@ -32,7 +32,7 @@ func setupImportCommand() *cobra.Command {
destName := stat.Name()
if len(args) > 2 {
destName = args[2]
if fs.CheckNameInvalid(destName) {
if core.CheckNameInvalid(destName) {
fmt.Println("invalid name: '" + destName + "'")
}
}
@@ -47,7 +47,7 @@ func setupImportCommand() *cobra.Command {
force, _ := cmd.Flags().GetBool("force")
var size int = 0
create := make([]fs.CreateResourcesParams, 0)
create := make([]core.CreateResourcesParams, 0)
copy := make(map[string]uuid.UUID)
ids := make(map[string]uuid.UUID)
targetRootID, _ := uuid.NewV7()
@@ -67,12 +67,12 @@ func setupImportCommand() *cobra.Command {
len = 0
}
size += len
if fs.CheckNameInvalid(d.Name()) {
return fs.ErrResourceNameInvalid
if core.CheckNameInvalid(d.Name()) {
return core.ErrResourceNameInvalid
}
ids[p], _ = uuid.NewV7()
parent := ids[path.Dir(p)]
create = append(create, fs.CreateResourcesParams{
create = append(create, core.CreateResourcesParams{
Parent: parent,
ID: ids[p],
Name: d.Name(),
@@ -92,13 +92,13 @@ func setupImportCommand() *cobra.Command {
}
fmt.Printf("Importing %d files (%d bytes) across %d dirs\n", len(copy), size, 1+len(create)-len(copy))
var conflictResolution fs.ResourceBindConflictResolution = fs.ResourceBindConflictResolutionError
var conflictResolution core.ResourceBindConflictResolution = core.ResourceBindConflictResolutionError
if force {
conflictResolution = fs.ResourceBindConflictResolutionDelete
conflictResolution = core.ResourceBindConflictResolutionDelete
}
err = f.RunInTx(func(f fs.FileSystem) error {
err = f.RunInTx(func(f core.FileSystem) error {
if _, err = f.CreateResourceByPath(args[1]+"/"+destName, targetRootID, stat.IsDir(), false, conflictResolution); err != nil {
if err == fs.ErrResourceNameConflict {
if err == core.ErrResourceNameConflict {
err = errors.New("resource with name '" + destName + "' already exist. use -f to overwrite")
}
return err
@@ -128,7 +128,7 @@ func setupImportCommand() *cobra.Command {
return &cmd
}
func copyContents(f fs.FileSystem, src string, id uuid.UUID) error {
func copyContents(f core.FileSystem, src string, id uuid.UUID) error {
fmt.Println("importing " + src + " to " + id.String())
in, err := os.Open(src)
if err != nil {
+4 -4
View File
@@ -10,7 +10,7 @@ import (
"github.com/jackc/pgx/v5/pgtype"
"github.com/shroff/phylum/server/internal/command/common"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
"github.com/spf13/cobra"
)
@@ -72,7 +72,7 @@ func setupLsCommand() *cobra.Command {
}
func formatPermissionsJson(j []byte) string {
p := make(map[string]fs.Permission)
p := make(map[string]core.Permission)
json.Unmarshal(j, &p)
if len(p) == 0 {
return ""
@@ -85,8 +85,8 @@ func formatPermissionsJson(j []byte) string {
}
type Grant struct {
Permission fs.Permission `json:"p"`
Timestamp int `json:"t"`
Permission core.Permission `json:"p"`
Timestamp int `json:"t"`
}
func formatGrantsJson(j []byte) string {
+3 -3
View File
@@ -6,7 +6,7 @@ import (
"github.com/google/uuid"
"github.com/shroff/phylum/server/internal/command/common"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
"github.com/spf13/cobra"
)
@@ -19,14 +19,14 @@ func setupMkdirCommand() *cobra.Command {
f := common.UserFileSystem(cmd)
path := args[0]
var recursive bool
var conflict fs.ResourceBindConflictResolution = fs.ResourceBindConflictResolutionError
var conflict core.ResourceBindConflictResolution = core.ResourceBindConflictResolutionError
if b, err := cmd.Flags().GetBool("parents"); err != nil {
fmt.Println("could not read flag 'parents': " + err.Error())
os.Exit(1)
} else {
recursive = b
if recursive {
conflict = fs.ResourceBindConflictResolutionEnsure
conflict = core.ResourceBindConflictResolutionEnsure
}
}
if _, err := f.CreateResourceByPath(path, uuid.Nil, true, recursive, conflict); err != nil {
+3 -3
View File
@@ -5,7 +5,7 @@ import (
"os"
"github.com/shroff/phylum/server/internal/command/common"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
"github.com/spf13/cobra"
)
@@ -25,9 +25,9 @@ func setupMvCommand() *cobra.Command {
force, _ := cmd.Flags().GetBool("force")
var conflictResolution fs.ResourceBindConflictResolution = fs.ResourceBindConflictResolutionError
var conflictResolution core.ResourceBindConflictResolution = core.ResourceBindConflictResolutionError
if force {
conflictResolution = fs.ResourceBindConflictResolutionDelete
conflictResolution = core.ResourceBindConflictResolutionDelete
}
if _, _, err := f.Move(src, args[1], conflictResolution); err != nil {
fmt.Println("cannot move'" + srcPath + "' to '" + args[1] + "': " + err.Error())
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"github.com/jackc/pgx/v5/pgtype"
"github.com/shroff/phylum/server/internal/command/common"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
"github.com/spf13/cobra"
)
@@ -32,7 +32,7 @@ func setupCreateCommand() *cobra.Command {
return &cmd
}
func createPublink(f fs.FileSystem, name, path string, password string, durationStr string, accesses int) error {
func createPublink(f core.FileSystem, name, path string, password string, durationStr string, accesses int) error {
r, err := f.ResourceByPathWithRoot(path)
if err != nil {
return err
+7 -7
View File
@@ -7,7 +7,7 @@ import (
"os"
"github.com/shroff/phylum/server/internal/command/common"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
"github.com/shroff/phylum/server/internal/core/user"
"github.com/spf13/cobra"
)
@@ -47,16 +47,16 @@ func setupSetfaclCommand() *cobra.Command {
return &cmd
}
func parsePermissionString(s string) (fs.Permission, error) {
func parsePermissionString(s string) (core.Permission, error) {
switch s {
case "none":
return fs.PermissionNone, nil
return core.PermissionNone, nil
case "read":
return fs.PermissionRead, nil
return core.PermissionRead, nil
case "write":
return fs.PermissionRead | fs.PermissionWrite, nil
return core.PermissionRead | core.PermissionWrite, nil
case "share":
return fs.PermissionRead | fs.PermissionWrite | fs.PermissionShare, nil
return core.PermissionRead | core.PermissionWrite | core.PermissionShare, nil
}
return fs.PermissionNone, errors.New("unrecognized permission: " + s)
return core.PermissionNone, errors.New("unrecognized permission: " + s)
}
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"os"
"github.com/shroff/phylum/server/internal/command/common"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
"github.com/spf13/cobra"
)
@@ -22,7 +22,7 @@ func setupSummaryCommand() *cobra.Command {
return &cmd
}
func printTrashSummary(f fs.FileSystem) {
func printTrashSummary(f core.FileSystem) {
items, size, err := f.TrashSummary()
if err != nil {
fmt.Println("cannot get trash summary: " + err.Error())
+3 -3
View File
@@ -14,7 +14,7 @@ import (
"github.com/shroff/phylum/server/internal/api/publink"
apiv1 "github.com/shroff/phylum/server/internal/api/v1"
"github.com/shroff/phylum/server/internal/api/webdav"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -106,8 +106,8 @@ func setupTrashCompactor() {
go func() {
for {
<-ticker.C
fs.TrashCompact(context.Background(), trashRetainDuration)
core.TrashCompact(context.Background(), trashRetainDuration)
}
}()
fs.TrashCompact(context.Background(), trashRetainDuration)
core.TrashCompact(context.Background(), trashRetainDuration)
}
@@ -1,4 +1,4 @@
package fs
package core
import (
"strings"
@@ -1,4 +1,4 @@
package fs
package core
import (
"errors"
@@ -1,4 +1,4 @@
package fs
package core
import (
"errors"
@@ -1,4 +1,4 @@
package fs
package core
import (
"github.com/google/uuid"
@@ -1,4 +1,4 @@
package fs
package core
import (
"errors"
@@ -1,4 +1,4 @@
package fs
package core
import (
"github.com/doug-martin/goqu/v9"
@@ -1,4 +1,4 @@
package fs
package core
import (
"net/http"
@@ -1,4 +1,4 @@
package fs
package core
import (
"github.com/jackc/pgx/v5/pgtype"
@@ -1,4 +1,4 @@
package fs
package core
import (
"strings"
@@ -1,4 +1,4 @@
package fs
package core
import (
"context"
@@ -1,4 +1,4 @@
package fs
package core
import (
"encoding/hex"
@@ -1,4 +1,4 @@
package fs
package core
import (
"github.com/google/uuid"
@@ -1,4 +1,4 @@
package fs
package core
import (
"strings"
@@ -1,4 +1,4 @@
package fs
package core
import (
"encoding/json"
@@ -1,4 +1,4 @@
package fs
package core
import (
"strings"
@@ -1,4 +1,4 @@
package fs
package core
import (
"github.com/jackc/pgx/v5"
@@ -1,4 +1,4 @@
package fs
package core
import (
"slices"
@@ -1,4 +1,4 @@
package fs
package core
import (
"context"
@@ -1,4 +1,4 @@
package fs
package core
import (
"encoding/base64"
@@ -1,4 +1,4 @@
package fs
package core
import (
"github.com/doug-martin/goqu/v9"
@@ -1,4 +1,4 @@
package fs
package core
import (
"github.com/google/uuid"
+4 -4
View File
@@ -6,7 +6,7 @@ import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
)
type Bookmark struct {
@@ -29,12 +29,12 @@ func scanBookmark(row pgx.CollectableRow) (Bookmark, error) {
return p, nil
}
func (m manager) AddBookmark(u User, resource fs.Resource, name string) (Bookmark, error) {
func (m manager) AddBookmark(u User, resource core.Resource, name string) (Bookmark, error) {
if name == "" {
name = resource.Name()
}
if fs.CheckNameInvalid(name) {
return Bookmark{}, fs.ErrResourceNameInvalid
if core.CheckNameInvalid(name) {
return Bookmark{}, core.ErrResourceNameInvalid
}
const q = `INSERT INTO bookmarks(user_id, resource_id, name, dir)
+5 -5
View File
@@ -7,9 +7,9 @@ import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/shroff/phylum/server/internal/core"
"github.com/shroff/phylum/server/internal/core/db"
"github.com/shroff/phylum/server/internal/core/errors"
"github.com/shroff/phylum/server/internal/core/fs"
)
var errInvalidEmailAddress = errors.NewError(http.StatusBadRequest, "invalid_email_address", "Invalid email address")
@@ -21,12 +21,12 @@ func (m manager) CreateUser(email, name string, noCreateHome bool) (User, error)
m := m.withDb(db)
var err error
var homeID pgtype.UUID
var home fs.Resource
f := fs.OpenOmniscient(db)
var home core.Resource
f := core.OpenOmniscient(db)
if !noCreateHome {
var err error
homePath := strings.TrimRight(Cfg.BaseDir, "/") + "/" + email
home, err = f.CreateResourceByPath(homePath, uuid.Nil, true, true, fs.ResourceBindConflictResolutionEnsure)
home, err = f.CreateResourceByPath(homePath, uuid.Nil, true, true, core.ResourceBindConflictResolutionEnsure)
if err != nil {
return err
}
@@ -39,7 +39,7 @@ func (m manager) CreateUser(email, name string, noCreateHome bool) (User, error)
}
if homeID.Valid {
if _, err := f.UpdatePermissions(home, user.ID, fs.PermissionRead|fs.PermissionWrite|fs.PermissionShare); err != nil {
if _, err := f.UpdatePermissions(home, user.ID, core.PermissionRead|core.PermissionWrite|core.PermissionShare); err != nil {
return err
}
}
+4 -4
View File
@@ -6,7 +6,7 @@ import (
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgtype"
"github.com/shroff/phylum/server/internal/core/fs"
"github.com/shroff/phylum/server/internal/core"
)
var Cfg Config
@@ -31,8 +31,8 @@ func scanUser(row pgx.CollectableRow) (User, error) {
return u, err
}
func (u User) OpenFileSystem(ctx context.Context) fs.FileSystem {
return fs.Open(ctx, u.ID, u.Home, u.Permissions&PermissionFilesAll != 0)
func (u User) OpenFileSystem(ctx context.Context) core.FileSystem {
return core.Open(ctx, u.ID, u.Home, u.Permissions&PermissionFilesAll != 0)
}
type Manager interface {
@@ -61,7 +61,7 @@ type Manager interface {
ResetUserPassword(user User, token, password string) error
// bookmarks.go
AddBookmark(u User, resource fs.Resource, name string) (Bookmark, error)
AddBookmark(u User, resource core.Resource, name string) (Bookmark, error)
RemoveBookmark(u User, id uuid.UUID) error
ListBookmarks(u User, since int64) ([]Bookmark, error)
}
@@ -1,4 +1,4 @@
package fs
package core
import (
"crypto/sha256"
@@ -1,4 +1,4 @@
package fs
package core
import (
"errors"