Skip to content

Commit

Permalink
some doc + fic Components
Browse files Browse the repository at this point in the history
  • Loading branch information
mandelsoft committed Jan 14, 2023
1 parent 84365b8 commit fb9b39c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/layerfs/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

// Package layerfs provides a virtual filesystem supporting a filesytem layer
// Package layerfs provides a virtual filesystem supporting a filesystem layer
// on top of a base filesystem, that is used to keep track of all changes
// done to the filesystem. Thereby the root filesystem is not changed.
package layerfs
24 changes: 24 additions & 0 deletions pkg/vfs/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2022 Mandelsoft. All rights reserved.
* This file is licensed under the Apache Software License, v. 2 except as noted
* otherwise in the LICENSE file
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Package vfs provides a virtual filesystem for GO. It is the main package
// providing the abstract interfaces and implementation-agnostic
// utility functions wrapped together with an implementation into a
// comprehensive user interface VFS.
// (see https://pkg.go.dev/github.com/mandelsoft/vfs)
package vfs
11 changes: 10 additions & 1 deletion pkg/vfs/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,14 @@ func Abs(fs FileSystem, path string) (string, error) {
return Join(fs, p, path), nil
}

// Rel determines the relative path from a source folder
// to a target file.
func Rel(fs FileSystem, src, tgt string) (string, error) {
if ok, _ := Exists(fs, src); ok {
if ok, _ := IsDir(fs, src); !ok {
return "", ErrNotDir
}
}
s, err := Canonical(fs, src, false)
if err != nil {
return "", fmt.Errorf("%s: %w", src, err)
Expand Down Expand Up @@ -305,13 +312,15 @@ func Rel(fs FileSystem, src, tgt string) (string, error) {
return Join(fs, sseq[is:]...), nil
}

// Components splits a path into its volume part and a list
// of path components.
func Components(fs FileSystem, p string) (string, []string) {
var seq []string
var b string

v, p := SplitVolume(fs, p)

for !IsRoot(fs, p) {
for p != "" && !IsRoot(fs, p) {
p, b = Split(fs, p)
seq = append(seq, b)
}
Expand Down

0 comments on commit fb9b39c

Please sign in to comment.