blang / vfs Goto Github PK
View Code? Open in Web Editor NEWVirtual filesystem library written in golang
License: MIT License
Virtual filesystem library written in golang
License: MIT License
Hello @blang
Maybe you know by any chance the s3 implementation of your Filesystem interface? If not would be interested in having one even if you claim "Only Stdlib" (this will bring aws sdk as a dependency)?
Thank you in advance.
Hi there,
I am interested to use this in my minimum docker image, basically the idea is that mount /tmp as tmpfs for the program to use. As it is minimum, there is no mount command, etc, just the app binary it self.
However from my test it seems not to use memory fs, that is after the docker container stop, I can see the file content is on the filesystem. So not sure if there is a problem with it, or the way I expect it to work is totally wrong.
Here is my snippet
package main
import (
"fmt"
"io/fs"
"io/ioutil"
"github.com/blang/vfs"
"github.com/blang/vfs/memfs"
u "github.com/sunshine69/golang-tools/utils"
)
func main() {
fmt.Println("started")
var osfs vfs.Filesystem = vfs.OS()
err := osfs.Mkdir("/adir", 0777)
u.CheckErr(err, "Error")
mfs := memfs.Create()
err = mfs.Mkdir("/tmp", 0777)
u.CheckErr(err, "Error")
ioutil.WriteFile("/tmp/test", []byte("hello my file"), fs.ModeAppend)
//Seems not work, after run I can inspect the container and the file does exist. If it is in memory it should not exist
}
Dockerfile
FROM stevekieu/golang-script:20210804 AS BUILD_BASE
RUN mkdir /app && mkdir /imagetmp && chmod 1777 /imagetmp
ADD . /app/
WORKDIR /app
ENV CGO_ENABLED=0 PATH=/usr/local/go/bin:/opt/go/bin:/usr/bin:/usr/sbin:/bin:/sbin
ARG APP_VERSION
RUN go mod download golang.org/x/net
RUN go build -trimpath -ldflags="-X main.version=v1.0 -extldflags=-static -w -s" --tags "osusergo,netgo,sqlite_stat4,sqlite_foreign_keys,sqlite_json" -o minimum-docker
CMD ["/app/minimum-docker"]
FROM scratch
# the ca files is from my current ubuntu 20 /etc/ssl/certs/ca-certificates.crt - it should provide all current root certs
ADD ca-certificates.crt /etc/ssl/certs/
COPY --from=BUILD_BASE /app/minimum-docker /minimum-docker
COPY --from=BUILD_BASE /imagetmp /tmp
ENV TZ=Australia/Brisbane
ENTRYPOINT [ "/minimum-docker" ]
Build the image, and run. After run use docker inspect the container name to find the UpperDir location, and get in there, the /tmp exists a file with the content. If it is memfs, then it should not exists any file at all.
Thanks
I was wondering why OpenFile doesn't return a pointer to a File, like its standard library counterpart. I would say that mirroring the standard library as closely as possible makes it a lot less painful to migrate to using vfs as a wrapper.
Right now there is no way to change the mtime of a mem file. os.Chtimes(path, atime, mtime)
i think would make a good addition as there is no other way of achieving this functionality.
IMHO normally it's unnecessary to use a slice pointer because a slice is a pointer type. I'd like hear your reasoning.
The current Filesystem interface is missing the Truncate() abstraction.
To embed a file system in a go app and then use this to write / read to said file system.
Embed creates a readonly file system so weren't sure if it would be possible
This is probably very silly, but I'd like to be able to run one of the files in the virtual filesystem. Is this something that's supported, or is this a terrible idea that I should immediately forget about?
Does this run on Windows? Or only on Linux and Mac?
To complement Lstat(path)
it would be nice if Readlink(path)
was added to the interface
I'm not sure if it is possible but I would like to see an example where we can create any kind of FS but it should be visible on underlying OS under some mount point. For instance, here is a code I came up with:
package main
import (
"log"
"os"
"time"
"github.com/blang/vfs"
"github.com/blang/vfs/memfs"
"github.com/blang/vfs/mountfs"
)
func main() {
// Create a vfs accessing the filesystem of the underlying OS
osfs := vfs.OS()
// Create a fully writable filesystem in memory
mfs := memfs.Create()
// Create a vfs supporting mounts
fs := mountfs.Create(osfs)
// Mount a memfs inside /memfs
fs.Mount(mfs, "/memfs")
f, err := mfs.OpenFile("file.efs", os.O_CREATE|os.O_WRONLY, 0)
defer f.Close()
if err == nil {
log.Println("created /memfs/file.efs")
_, err := f.Write([]byte("Some content"))
if err != nil {
log.Println("unable to write content to file.efs", err)
}
} else {
log.Println("failed to create /memfs/file.efs", err)
}
for {
time.Sleep(10 * time.Second)
}
}
So, if I compile and run it it serves as a daemon, but I would like to see my /memfs
from underlying OS shell. Is it possible?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.