Repository navigation
Releases
v1.0.0-rc.8
Eighth release candidate: gitfs, a read-only file system for a commit of
a remote git repository on GitHub, GitLab or any other git server. The
other modules are unchanged.
Added
gitfs, a new module:gitfs.New(ctx, repoURL, ref, opts)opens a
branch, tag or commit of a repository URL as a read-only file system, and
fs.File("git+https://github.com/owner/repo.git@v1.0.0/README.md")
reads its files afterfs.Register. It speaks the git smart HTTP
protocol version 2 with the standard library only, without a git binary,
go-git or a clone on disk.- Nothing is downloaded up front:
Newresolves the ref with two
requests, directories load when a path below them is accessed and file
content when it is read, with a cache ofOptions.CacheSize. On
github.com, the GitHub REST API supplies the file sizes and a file is read
from raw.githubusercontent.com: reading one file in the root directory
of the latest version takes five requests,Newincluded. - Authentication with an access token (
Options.Token) or a username and
password, also from the user info of the URL, which never appears in the
prefix, IDs or error messages. - Limits for content from a hostile server:
Options.MaxObjectSizeper
file,Options.MaxFetchSizeper response including a fixed overhead per
object, at most 2M files and directories, and paths of at most 4096
bytes. Every object is verified against its ID and every packfile
against its checksum. - Symbolic links, submodules and names that can't be file names of a
checkout (.git, names with a backslash, names that are not valid UTF-8)
are not exposed. - A tutorial step that prints the README of this repository through
gitfs, and gitfs in the README, the connect-a-backend how-to and the
support matrices.
v1.0.0-rc.7
Seventh release candidate: gofs, a command line tool for files on every
file system of go-fs, also between them. The library modules are unchanged.
Added
cmd/gofs, a command line tool for local files, HTTP, FTP, SFTP, SMB,
WebDAV, S3, Azure Blob Storage and Dropbox:ls,stat,cat,put,
cp,mv,rm,mkdir,touch,hash(Dropbox content hash, SHA-256
or MD5) andcmp, also across file systems, like
gofs cp -r s3://bucket/dir sftp://host/dir. The remote file systems
connect on first use with credentials from environment variables and the
setups ofssh, the AWS CLI andaz login;gofs envlists the
variables and which of them are set, never their values. Install it with
go install github.com/ungerik/go-fs/cmd/gofs@latestor download it from
the release.putkeeps an existing file when stdin fails or the command is
interrupted: S3, Azure Blob Storage, Dropbox, WebDAV and FTP discard the
incomplete upload, and on the local file system, SFTP and SMB the file is
replaced by renaming a complete temporary file over it.rmrefuses a path that ends with.or.., also percent-encoded in a
URI, before it removes anything.- The Azure credentials of the environment are only sent to the storage
account host, the FTP and SMB passwords of the environment never to an
anonymous FTP login or an SMB guest session, and errors never print the
passwords of URIs. - Release archives of
gofsfor Linux, macOS and Windows on amd64 and
arm64 with SHA-256 checksums, built by the newrelease-gofsworkflow
for every published release.
Changed
cmd/gofsrequires the go-fs modules of its own release without
replacedirectives, unlike the backend modules, so thatgo install
works;gofs versionprints both versions. The new./gofs-require.sh
sets them in the release PR before the tags exist, the CI and
./test-workspace.shbuildcmd/gofswithout the workspace through it,
andtag-release.shrefuses a release whosecmd/gofs/go.sumdoesn't
match the modules.
v1.0.0-rc.6
Sixth release candidate: the conformance suite now checks that copies and
moves never lose data when the destination is another name of the source,
and covers the optional path, hidden, ownership and watch interfaces, the
listing and write helpers of File and its io/fs view. The new checks
found a move through a linked directory under another case that deleted
the file; it is refused now.
Fixed
- The copy-then-delete fallback of
fs.Moveno longer deletes a file that
one path reaches through a link to a parent directory under another case
of its name on a case-insensitive server, like a move ofreal/src.txt
toLINK/SRC.TXT, or oflink/src.txttoREAL/SRC.TXT, withlink
pointing toreal. The fallback runs within a file system that is not
local, has symbolic links and no nativeMove, also through
aSubFileSystemof one, and through anOverlayFileSystem, also one
with an sftpfs or smbfs layer; sftpfs and smbfs on their own move
natively on the server. It compared the spellings of the paths before
resolving their links, took the destination for another file, copied the
file onto itself and removed it. It now refuses such a move with an error
wrappingos.ErrInvalid.
Added
fstest.RunConformancechecks that copies and moves never lose data when
the destination names the source another way (Aliases): a link to the
source or to a parent directory, another hard link, another case or Unicode
normalization of the name, also through a linked directory, and the root
of aSubFileSystem. The newConfig.HardLinklets a file system with
hard links run those checks; sftpfs and smbfs run them against their test
servers.fstest.RunConformancealso checksURIFileSystem,VolumeNameFileSystem,
AbsPathFileSystem(PathInterfaces),HiddenFileSystem(Hidden),
UserFileSystemandGroupFileSystem(Ownership),WatchFileSystem
(Watch), the listing helpers ofFileand itsio/fsviewFile.StdFS
withtesting/fstest.TestFS(ListingHelpers), and the write helpers of
File(WriteHelpers). A file system that doesn't pass a new check yet can
skip it withConfig.Skip; s3fs and azureblobfs skip
ListingHelpers/StdFSfor now: their listings andStatreport
different modification times for some entries, and azureblobfs opens
a path with a backslash like one with a slash.
v1.0.0-rc.5
Fifth release candidate: s3fs works with more S3-compatible services:
Cloudflare R2, Backblaze B2, Wasabi, DigitalOcean Spaces, Google Cloud
Storage and Hetzner Object Storage, see the client settings for each in the
s3fs README. A move between two Unicode normalizations of a file name, which
R2 stores as one object, is refused instead of deleting the file.
Changed
- s3fs multipart uploads and ranged downloads use checksums only if the
client is configured withWhenSupported, whichconfig.LoadDefaultConfig
sets. The transfer manager sent CRC32 checksums and validated downloads
also for a client ofs3.Newwithout checksum options, which sends none,
so on services without these checksums, like Backblaze B2 and Google Cloud
Storage, uploads ofMultipartUploadThresholdbytes or more failed while
smaller ones worked. Downloads of a client whose response checksum
validation is not set are no longer validated. - s3fs
CopyFiledownloads and uploads an object that the service refuses
to copy with501 Not Implementedor413, like Cloudflare R2 and
Backblaze B2 the conditions ofUploadPartCopyfor objects above 5 GiB,
with the metadata of the source but without its tags. A download whose
Content-LengthorContent-Encodingdiffers from the object, like the
decompressed data of a gzip object on Google Cloud Storage, is not uploaded,
CopyFilereturns anfs.ErrUnsupportederror then.Touchreturns an
fs.ErrUnsupportederror for such a service. On Google Cloud Storage
endpoints, which have noUploadPartCopy, objects of every size are
copied withCopyObject.
Fixed
- s3fs
ListDir,ListDirRecursiveandRemoveAllreturn an error for
a truncated listing page without a new continuation token. The SDK
paginator ended such a listing early, soListDirreturned a part of the
directory andRemoveAllreported success after deleting a part of it,
or repeated pages for a token it had sent before. - s3fs multipart uploads and copies into Wasabi buckets with an
AbortIncompleteMultipartUploadlifecycle rule failed, because the SDK
can't parse the ISO 8601 date that Wasabi sends inx-amz-abort-date. - s3fs copies above 5 GiB sent the part checksums that a service returned
for an upload created without a checksum algorithm, which services that
check them can refuse as a mismatch of the checksum type. - s3fs
Removesucceeds whenDeleteObjectanswers404for an object that
another client deleted afterRemovefound it, like Google Cloud Storage
does where S3 succeeds. - s3fs
RemoveAlldeletes the objects one by one on a service that answers
DeleteObjectswith501 Not Implemented, like Google Cloud Storage,
and sendsDeleteObjectsonly for the first batch then. - s3fs
RemoveAllkeeps the body of everyDeleteObjectsrequest below the
1 MiB that Ceph RGW accepts, the server of Hetzner and DigitalOcean Spaces,
which 1000 long keys exceeded. - The copy then delete fallback of
fs.Movewithin a file system that is not
local and has no nativeMove, like s3fs, refuses a destination that may be
another Unicode normalization of the source name and has its size,
modification time and permissions, like it refuses another case of the name.
On Cloudflare R2, which matches keys by their Unicode normalization, the
move copied the object onto itself and then deleted it.
v1.0.0-rc.4
Fourth release candidate: copies and moves within sftpfs, smbfs, ftpfs and
other file systems that are not local no longer truncate or delete a file
that the destination reaches under another name, a move into a zip or tar
writer is refused instead of losing the source, ftpfs RemoveAll can no
longer be tricked into deleting through a link, EnsureRegistered checks
its prefix like Register, passwords stay out of httpfs errors, and more
Shift-JIS zip names decode.
Changed
fs.Moveinto a write-only file system, like azipfs.Writeror
tarfs.Writer, fails with an error wrappingfs.ErrWriteOnlyFileSystem
before it copies anything. It removed the source as soon as its entry was
in the writer's stream, but the archive is only written byClose, so
a failingCloselost the moved files. Copy withfs.CopyRecursive,
close the writer and remove the source afterClosesucceeded.- ftpfs
RemoveAllfails for a directory whoseLISTlisting, which tells
a directory from a symbolic link, has a line that the FTP client library
dropped because it can't parse it, like the line of a FIFO, a device or
a socket, or one with a five-digit year. Empty lines and thetotal N
line ofls -lare fine. On servers with MLST support this is the
listing of the parent of every directory whoseDELEfailed, on servers
without it the listing of the removed directory. The check for an entry
named-aruns after every such listing instead of once per directory.
Fixed
fs.CopyFileof a symbolic link onto the file it points to, of a file
onto a link to it, or through a link to a parent directory, within one
file system that is not local and has no nativeCopyFile, like sftpfs
and smbfs, truncated the file before reading it. An existing destination
is now compared with every link resolved, also between a
SubFileSystemand its parent, and the copy is a no-op like for local
files. The copy then delete fallback offs.Moverefuses such paths as
the same file with an error wrappingos.ErrInvalidinstead of removing
the source.fs.CopyFileof a file onto another hard link of it, or onto another
case of its name on a case-insensitive server, within sftpfs, smbfs,
ftpfs or another file system that is not local and has no native
CopyFile, truncated the file before reading it (reproduced on Samba).
These servers can't tell such a destination from another file, so
a destination with the size, modification time and permissions of the
source is now written as a new file in its directory that then replaces
it with a move. That copy needs the permission to create, rename and
remove files in the destination directory, which an overwrite in place
doesn't, and the replaced file gets the owner and permissions of a new
file. A copy onto a symbolic link replaces the file it points to and
keeps the link, and when the move onto the destination fails after it
removed the destination, the new file is kept and the error names it.
The copy then delete fallback offs.Moverefuses a destination that
only differs in case and has those attributes, and a move between
aSubFileSystemand its parent that is not local uses the native
Moveof the parent, which renames on the server, except for a symbolic
link, which is handled like between other file systems.fs.Moveof the root directory of aSubFileSystemto another file
system copied the whole directory before it failed to remove the root;
it is refused with an error wrappingos.ErrInvalidbefore anything is
copied, likeSubFileSystem.Moverefuses it.- An ftpfs
RemoveAllcould delete the files that a symbolic link points
to: a client that could write into the directory could make the client
library drop the line of its link and add a forged directory line with
the link's name through a file name with a line feed (see Changed). - On FTP servers without MLST support that expand glob characters in the
path argument ofLIST, like wu-ftpd and ProFTPD withUseGlobbingbut
withoutmod_facts, ftpfs listed another directory for a path with*,
?or[, soStatandListDirdescribed its entries andRemoveAll
could take a symbolic link for a directory and delete the files it points
to. Such a path, and a relative one that begins with-, is now listed
after aCWDto it withLISTwithout an argument, and the working
directory is changed back; a failed change back closes the connection. fs.EnsureRegisteredregistered a prefix with a slash or backslash
before its://, whichfs.Registerrefuses, so after the lastfree
its URIs were local paths. The prefix is refused with an error wrapping
os.ErrInvalidbeforecreateis called, and so is a prefix alias of
the created file system.- The errors of
httpfs.Newfor an invalid prefix contained the password
of a prefix with user info; the error for a prefix with a query also
leaves out the query now. The errors offs.CopyRecursivefor
a directory copied into itself redact passwords like the other errors. - zip names: an Info-ZIP Unicode Path field was ignored for Shift-JIS
names where the ASCII second byte of a double-byte character is followed
by the same letter, likeアA日.txtorエリアA計画.xlsx, which then
showed the CP-437 decoding of the stored name.
v1.0.0-rc.3
Third release candidate: the zipfs and tarfs readers and writers share
their entry info, conflict checks and directory creation instead of two
copies, backends share one NUL check, and the README is rewritten for a
first-time reader.
Added
fsimpl.ValidateNoNUL(subject, s)returns an error wrapping
os.ErrInvalidfor a path or name with a NUL character, next to
fsimpl.CheckNoBackslash, for backends that can't store such names.
sftpfs, webdavfs, dropboxfs and tarfs use it; their error messages are
unchanged.
Changed
- The root directory of a zip or tar archive with an explicit
./or/
entry has the header of that entry asFileInfo.Sys, a
*zip.FileHeaderor*tar.Header, like every other entry; it was nil.
The root of an archive without such an entry still has noSys. - The errors of
zipfsandtarfsfile systems afterClosename the
file system and its URI prefix, like httpfs andMemFileSystem:
Tar reader filesystem with prefix tar://<id>: file system is closed.
tarfs returned the barefs.ErrFileSystemClosed, so compare with
errors.Is(err, fs.ErrFileSystemClosed), not==. - The README starts with a one-line pitch, an install section, a short
example that runs one function on local disk, HTTP and S3, and the
feature list. Thego getlines of the backend READMEs and the connect
how-to fetch the core module together with the backend, because a
backend fetched alone in a fresh module can't resolve the placeholder
version of the core module, and Go examples that usefs.*import the
core module.
v1.0.0-rc.2
Second release candidate: zip archives get one name rule for every writer
and UTF-8 names on read, and a copy, move or rename into a file system that
can't write a name, like a zip writer or an S3-compatible server, fails
before it writes anything instead of at that name.
Added
fs.ValidateNameFileSystem, an optional interface withValidateName(name)
for file systems that can't write some names that their separator allows.
fs.CopyFile,fs.CopyRecursive,fs.Move,File.MoveToand
File.Renamecheck the names they write with it, also through a
SubFileSystemorOverlayFileSystemto the file system that gets the
writes, so they fail before they write anything instead of at the first
such name.CopyRecursivechecks the files and links that match its
patterns, and every directory.File.MakeAllDirschecks the names of the
missing directories, also the parent directories that a copy or move
makes. Their errors wrap the error ofValidateName, which tells why.
Existing entries are read with every name, and copied and moved with
their names within the file system, which holds them. The write methods
of a file system itself, likeOpenWriter, are not checked. sftpfs,
ftpfs, webdavfs, smbfs, s3fs, azureblobfs, dropboxfs and the zipfs and
tarfs writers implement it with the names that their servers or formats
can't write, see the READMEs: a backslash (unless
Options.AllowBackslashInNamesfor sftpfs, ftpfs and webdavfs), a NUL
character, at which an SFTP server would end a path, CR and LF, which
would inject an FTP command, the characters that SMB refuses, the device
names and trailing dots that Windows servers refuse, invalid UTF-8, which
the remote backends don't write, control characters, which the XML
listings of S3 and Azure Blob Storage can't hold, and trailing dots,
which Azure removes.fstest.RunConformancechecks theValidateNameof a file system that
implementsfs.ValidateNameFileSystem: names that every file system
writes are valid, errors wrapos.ErrInvalid, a copy to a rejected name
writes nothing, and every accepted name of a probe list is written, read
back and listed with that name.fstest.MockFullyFeaturedFileSystemimplementsfs.ValidateNameFileSystem
with the hookMockValidateName; without it every name is valid.
Changed
fs.ZipandZipMemFilesreject the names that are not valid in a zip
archive with an error wrappingos.ErrInvalid, not only the names that
UnzipToMemFilesrejects: names that are not valid UTF-8, which zip
readers decode as CP-437, that contain a control character like NUL, a
line or paragraph separator, a bidirectional embedding, override or
isolate, which can disguise an extension (evil\u202etxt.exe), or a
colon, which marks a drive letter on Windows, and names longer than the
65535 bytes of a zip header. The name of aFileReaderthat is not a
MemFilehas to be a clean, slash separated path (io/fs.ValidPath, not
a//b.txtordir/for a file); theFileNameof aMemFileis cleaned
as before.archive/zipwrites all of these names, except a name that is
too long, which it rejects after adding it to the central directory.
zipfs.Writerrejects the same characters and lengths in its cleaned
paths. Names that only Windows can't extract, likewhat?.txt, are not
checked.fs.UnzipToMemFilesandzipfs.Readerreturn entry names as UTF-8: a
name without the UTF-8 flag is taken from its Info-ZIP Unicode Path extra
field if it has one that keeps the ASCII parts of the stored name and
only replaces its bytes of another code page and the?and_
substitutes, without a control or bidirectional formatting character, so
it can't give the entry another extension, directory or drive letter
thanarchive/zipshows, also not one that only looks like another,
else a name that is not valid UTF-8, like the umlauts of old Windows
tools, is converted from CP-437, the encoding of names without the flag.
archive/zipreturns the stored bytes, whichZipMemFilesand
zipfs.Writernow reject, so the MemFiles and files of such an archive
couldn't be zipped again.- Copies and moves from another file system into a backend fail before
they write anything at a name thatValidateNameof the backend rejects,
also where the server wrote it before: a name that is not valid UTF-8
into sftpfs, ftpfs and webdavfs on Linux servers, a backslash into s3fs,
which AWS S3 stores but S3-compatible servers reject, and Windows device
names and trailing dots or spaces into smbfs, which Samba writes. Copies
and moves within one of them keep these names. tarfs.Writerrejects paths with a NUL character, whicharchive/tar
failed to write withoutos.ErrInvalid, and paths that are not valid
UTF-8, which the PAX format requires, with an error wrapping
os.ErrInvalid. sftpfs rejects paths with a NUL character, at which the
server would end the path and use another file.
Fixed
-
File.Rename, andfs.MoveandFile.MoveTowithin one file system,
check the new name like a copy into the directory does: on Windows a name
that Windows writes to another entry, likereport.toreport,
replaced that file, and names with one of< > " | ? *reached the file
system.fs.CopyFileto a local name that the local file system doesn't
write fails before it makes the parent directories, likefs.Move. -
A
zipfs.Writerpath longer than 65535 bytes made the whole archive
unreadable:archive/zipadds the name to its central directory before
it rejects it, soClosereturned no error and wrote a corrupt archive.
v1.0.0-rc.1
First release candidate: file URIs follow RFC 8089 on every platform, copies
and moves refuse what would overwrite, misplace or leave their destination
instead of losing data (name collisions, invalid and reserved names, special
files, the same file through another path), ftpfs RemoveAll no longer
deletes through symbolic links on servers that show them, azureblobfs
handles blobs with snapshots and moves blobs natively, pinned to their
ETags, and File.URL is renamed to File.URI. All modules are tagged in
lockstep, the tools module is not tagged.
Changed
-
Only a
://with no slash or backslash before it is the scheme of a URI:
a string like/cache/https://xis the local path/cache/https:/x
instead of theInvalidfile system.s3://bucket/keywithout
a registered s3fs staysInvalid, like every URI of an unregistered
scheme.fs.Registerrefuses a prefix with a separator before its://,
whose URIs would be local paths afterUnregister, and so do the s3fs
Options.Prefixcheck and the conformance suite. -
File.URL()is renamed toFile.URI(),fs.FileURLstofs.FileURIs,
andfsimpl.PathHelper.URLandLocalFileSystem.URLtoURI. The value
is a go-fs URI, which percent-encodes only%: names keep their spaces,
?and#, so it is no RFC 3986 URL to pass tonet/url, an HTTP client
or a browser. The value is unchanged, except for the file URIs of
Windows and UNC paths, which follow RFC 8089 now, see below. -
fs.ReadHeaderandfs.ReadHeaderStringtake actxas first argument
like the other functions that read content. It is checked before the file
is opened and between the reads. A reader that fails with
io.ErrUnexpectedEOF, like a truncated stream, is an error now instead of
a short header. -
fsimpl.ReadonlyFileBuffer,NewReadonlyFileBufferand
NewReadonlyFileBufferReadAllare renamed toReadOnlyFileBuffer,
NewReadOnlyFileBufferandNewReadOnlyFileBufferReadAll, the spelling of
every other read-only identifier. -
File URIs follow RFC 8089.
File.URI()(wasFile.URL()) of a Windows
path isfile:///C:/dir/fileinstead offile://C:/dir/file, and of a
UNC pathfile://server/share/file, of the serverslocalhostand~
and of a server likeC:file:////localhost/share/file, because as host
localhostis a local path,~the home directory andC:the drive.
Only the formfile://is recognized, the short formsfile:/pathand
file:pathof RFC 8089 are relative local paths. Parsing accepts
file://localhost/…, on Windows also the oldfile://C:/…form, and maps
file://server/share/…to the UNC path\\server\share\…. On other
platforms a file URI with a host other thanlocalhostresolves to the
Invalidfile system instead of a path relative to the working directory.
So does a relative URI that v0 wrote or accepted, like
file://data/uploads, which names the hostdata(on Windows the UNC
path\\data\uploads). The hosts.,..and?name no host on any
platform:file://./xresolves to theInvalidfile system, also on
Windows, where it would be the device path\\.\x.File.URI()of a
relative path that can't be made absolute, because the working directory
can't be determined, isfile://./…, which names no file.file://and
file://localhostwithout a path have the empty path instead of the
working directory: they resolve to the local file system, whose operations
fail for the empty path withfs.ErrEmptyPath, and the Files derived from
them, like byJoinorDir, have the empty path too, with the URI
file://. A Windows long path of a drive or a UNC path keeps its prefix,
\\?\C:\xhas the URIfile:////?/C:/xlike in beta.3, because the
prefix keeps names that Windows would normalize, like a trailing dot.
Other paths of the device and file namespaces, like\\.\COM1,
\\?\Volume{…}\xand\??\PhysicalDrive0, get a URI that names no file.
On Windows a file URI with a host is a UNC path, so opening aFilefrom
an untrusted file URI can connect to that host over SMB, also for forms
without a host likefile:////server/share/x; check the resolved path,
seeParseRawURI. -
sftpfs,ftpfsandwebdavfsreject a path with a backslash with an
error wrappingos.ErrInvalid, insftpfsalso a symbolic link target
and inftpfsa listed link target thatStatfollows.
For their separator/the backslash is part of a name, but a server on
Windows takes it for a separator and resolves.., so a name like..\x
from aSubFileSystem, an archive orCopyRecursivereached a file outside
of its directory, like the backslash rule ofsmbfs. The new
Options.AllowBackslashInNamesof the three backends allows backslashes
for servers that store them in names, like servers on Unix.
Added
azureblobfs.Options.DeleteSnapshotsdeletes the snapshots of a blob
together with it inRemove,RemoveAllandMove. Without it, removing
a blob with snapshots keeps the blob and returns an error wrapping the new
azureblobfs.ErrSnapshotsPresent,RemoveAllchecks the whole tree for
snapshots before it deletes anything, andMovebefore it copies anything.azureblobfsimplementsfs.MoveFileSystem:Movecopies the blobs
server-side and deletes the source after every copy succeeded. Every copy
and delete is pinned to the ETag the source blob had whenMovefound it
(x-ms-source-if-match,If-Match), so a blob that another client
replaces during the move is kept, andMovereturns an error saying that
it changed while it was being moved. A source blob that another client
deletes before its copy stopsMovewith an error wrapping
os.ErrNotExist. Every copy is pinned to its destination too: to a
missing destination, like every blob of a directory, with
If-None-Match: *, onto an existing destination blob withIf-Matchand
the ETagMovefound. A blob that another client creates at the
destination or below a moved directory, or a newer version of the
destination blob, is not overwritten:Movestops with an error wrapping
fs.ErrAlreadyExists(os.ErrExist) for it. Both errors copy nothing
more and delete no source blob. When the SDK retries a copy whose answer
was lost and the retry fails the destination condition against the copy
Azure already made,Moverecognizes the completed copy of the source
blob it found (copy source, size, Content-MD5, completed after the source
was last modified) and finishes the move. A copy of a snapshot or version
of the source (asnapshotorversionidparameter in the copy source)
is not taken for that copy. A source blob that another client deletes
after its copy, or whose delete the SDK retried after a lost answer, is no
error also when the pinned delete is answered with 412 instead of 404, as
Azurite does:Movelooks the blob up after a 412 and goes on if it is
gone. Only a move within one file system
is pinned;fs.Moveto another container or file system copies and calls
RemoveAll, which isn't. The generic move copied first and
then failed to delete a source with snapshots, after it had replaced the
destination.fsimpl.CheckNoBackslashreturns the error of the backslash rule of the
remote file systems with the separator/, whichftpfs,sftpfs,
webdavfsandsmbfsshare.
Fixed
-
fs.CopyFileandfs.Moveinto an existing directory joined the name of
the source unchecked: a name like..\evil.txtof a source on a file
system with the separator/was written outside of the directory on
a file system with the separator\, andMoveremoved the source. On
WindowsNULora:bwent to a device or an alternate data stream. A name
that is not one valid name in the directory is now an error wrapping
os.ErrInvalid, like forCopyRecursive. -
ftpfsRemoveAllrefuses a directory whose name its listing lists more
than once, like for a file whose name contains a line feed followed by
a forged line that lists a directory with the name of a link. On servers
without MLST support the listing is all that tells a directory from
a link, so it deleted the files that such a link points to. Servers that
hide dotfiles fromLIST, like vsftpd by default, hide them fromftpfs
too; this is documented. -
CopyRecursiveandMovefail withErrEmptyPathwhen the source or the
destination has the empty path, like a file URI without a path (file://,
file://localhost). Their same-file checks took that path for the working
directory: copying the working directory tofile://returned nil without
copying anything, and so didMovefromfile://tofile://localhost. -
ftpfson servers without MLST support:Stat,Remove,RemoveAll,
MoveandMakeDirfind a symbolic link whose name contains->, and
ListDirandListDirRecursiveof such a link to a directory list the
directory. The FTP client library cuts theLISTline of a link at the
first->, so ftpfs reported such a link as missing, andRemoveAll
returned nil and kept it.ListDirstill names the link by the part
before the first->. -
fs.CleanFilePathandfs.JoinCleanFilePathdidn't decode the
percent-encoded characters of a URI, unlikeFileandfs.ParseRawURI:
file:///tmp/a%25bwas the path/tmp/a%25binstead of/tmp/a%b, and
s3://bucket/a%20bthe keya%20binstead ofa b. They resolve the
first part likeFilenow, the other parts are names, used verbatim.
LocalFileSystem.CleanPathandSplitPathdecode a file URI too. -
File.TrimExttrimmed the string of the File instead of its path, so it
could cut at a dot before an encoded separator%2Fof a URI, or on
Windows at a dot in a directory or host name of a file URI, like
file://fileserver.corp/share/README, wh...
v1.0.0-beta.3
Third beta: an empty indent of the …Indent writers puts every element on its
own line, and azureblobfs handles unexpected answers without panicking. All
modules are tagged in lockstep, the tools module is not tagged.
Changed
WriteJSONIndentandWriteXMLIndentofFileandMemFile, and
NewMemFileWriteJSONIndent/NewMemFileWriteXMLIndent, put every element on
its own line without indentation whenindentis empty, instead of writing
the compact output ofWriteJSON/WriteXML. For JSON that is the output of
beta.1'sWriteJSON(ctx, v, "")again. For XML the newlines are new and are
read back as part of mixed content (character data next to child elements);
WriteXMLstill adds no whitespace. A NUL byte, which is invalid in XML,
directly before a<in content the encoder writes without escaping
(,innerxml,,cdata,,comment, names andxml.Marshalertokens) is
removed together with the line markers.- Backend dependencies are bumped:
azureblobfs(azcore v1.23.3, azblob
v1.8.2),s3fs(AWS SDK v1.47.4, service/s3 v1.114.5, transfermanager
v0.4.19),sftpfs(pkg/sftp v1.13.12) andsmbfs(geoffgarside/ber v1.2.0,
hashicorp/go-uuid v1.0.4).
Fixed
azureblobfsreturns an error instead of panicking with a nil pointer for a
download answered with 304 Not Modified (azblob v1.8.2 returns it without
body and without error) and for a listing answer without aBlobselement.- The reader of
azureblobfsOpenReaderreturns the bytes at its position
when a server ignores the Range header, instead of the start of the blob. azureblobfsWriteAlluploads at most 4 blocks in parallel like
OpenWriter, azblob v1.8.1 raised its default to 8 to 96.
v1.0.0-beta.2
Second beta. It fixes the bugs of a full review of beta.1 (data loss,
security, crashes) and settles the API decisions that freeze with v1.0.0.
Most breaking changes fail to compile, so the compiler finds the call sites;
docs/MIGRATION_v1.md lists them in "Upgrading from v1.0.0-beta.1". All
modules are tagged in lockstep, the tools module is not tagged.
Changed
- Constructors never register implicitly.
New…/Dial…return the file
system, and an error where construction can fail, and don't register it;…AndRegistervariants register
and return only anerror. Every constructor that used to register under a
plain name changed its signature, so old call sites don't compile instead of
silently losing the registration:fs.NewMemFileSystem(opts *MemFileSystemOptions, initialFiles...)(ID, separator, volume and
read-only are options;WithID,WithVolumeandNewSingleMemFileSystem
are gone),zipfs/tarfsNewReader/NewWriter(file, id),
multipartfs.New(form, id)andmultipartfs.NewFromRequest(was
FromRequestForm),s3fs.NewLoadDefaultConfigand
azureblobfs.NewFromConnectionString. Temporary file systems are used with
New,fs.Registeranddefer f.Close(). - Registry. A URI matches a prefix only at a boundary (the URI ends, the
prefix ends with/, or/or the separator follows), and the longest
match over prefixes and aliases wins, sos3://logsno longer serves
s3://logs-archive/…andftp://user@filesno longer serves
ftp://user@files.example.com/….Registerreturns an error
(ErrAlreadyRegistered) when another file system holds the prefix and is
not reference counted any more;UnregisterandIsRegisteredcompare
instances.fs.EnsureRegisteredis an atomic get-or-create with one shared
connect for concurrent callers and reference countedfreefunctions.
Closealways unregisters. - Per-instance options in every backend, no mutable package config.
s3fs.New(client, bucket, *Options),azureblobfs.New(ctx, client, *Options),dropboxfs.New(ctx, token, *Options),sftpfs.Dial(ctx, address, *Options)(password, public keys, agent and keyboard-interactive
viaAuth, host key callback that fails closed, timeouts, keep-alive,
retries,DialContext),ftpfs.Dial(ctx, address, *Options)(credentials
moved into the options),smbfsOptions.DialContext. The package
variabless3fs.MultipartUploadThreshold/MultipartDownloadThreshold,
sftpfs.MaxConnectRetries/InitialRetryBackoff/URLHostKeyCallbackand
httpfs.Clientare gone; allDefaultPermissions/DefaultDirPermissions
are constants.httpfshas an exportedFileSystemtype with
New(prefix, *Options)andNewAndRegister, for example to use an
authenticating client forhttps://api.example.com/; itsCloseunregisters it,
DefaultandDefaultTLSstay registered. - Error contract. The typed errors (
ErrDoesNotExist,ErrPermission,
ErrAlreadyExists,ErrIsDirectory,ErrIsNotDirectoryand the new
ErrDirectoryNotEmpty) are created for aFileReader;File()returns
(File, bool), the newFileReader()the passed reader, and every typed
error matcheserrors.Is(err, fs.ErrIsDirectory{})and so on. They stay
comparable for non-comparable readers likeMemFile, soerrors.Isnever
panics.ErrEmptyPathis a constant that no longer wrapsos.ErrNotExist,
soRemove("")is an error. Files of unregistered prefixes report
ErrInvalidFileSystemwith the URI (password redacted) instead of
"write-only". New sentinelsErrFileSystemsDoNotMatchand
ErrAlreadyRegistered. Error messages never contain passwords, SAS
signatures or URL queries. - Move, Rename and CopyFile onto an existing destination behave the same
on every file system: an existing file is replaced, an existing directory
is an error wrappingos.ErrExist(ErrIsDirectoryforCopyFile) and is
never merged or deleted, a directory onto a file isErrIsNotDirectory,
moving a directory into itself is an error wrappingos.ErrInvalid. - Implementer interfaces.
MoveFileSystem.Moveand
TruncateFileSystem.Truncatetake a ctx;SymbolicLinkFileSystemhas
Lstatinstead ofIsSymbolicLink;XAttrFileSystem.SetXAttrtakes the
portableXAttrFlags(XAttrCreate,XAttrReplace);PermissionsFileSystem
embedsFileSystem;RenameFileSystemandListDirMaxFileSystemare
removed (Rename is a Move within the directory). NewWriteAborter, which
the package uses to discard uploads that commit on Close when a copy fails,
andURIFileSystemfor file systems whose paths are escaped URIs.
fsimpl.PathHelperis no longer embedded as an exported field and lost
IsAbsPath,AbsPathandIsHidden.Eventhas go-fs owned constants
(EventCreate, …) instead of fsnotify values, and the callbacks of one
watch are called serially in event order. - File API.
File.Rename/Renameftake a ctx (without native move they
copy);File.Lstatis new andReadSymbolicLinkreturns the raw target
string;FileReadergainsStatandIsSymbolicLink;Globyields
iter.Seq2[File, error]with pattern, listing and ctx errors,MustGlobis
removed;WriteJSON/WriteXML(ctx, input, perm...)and
WriteJSONIndent/WriteXMLIndent(ctx, input, indent, perm...)(same for
MemFileandNewMemFileWrite*);ServeFileHTTP(w, r, file, contentType string);TempFile(ext)/CreateTempFile(ext);
ContentHashFuncFrom(newHash func() hash.Hash);CopyFileBuf(ctx, src, dest, buf []byte, perm...);fs.ReadAll(ctx, r)/fs.WriteAll(ctx, w, data)(wereReadAllContext/WriteAllContext);ReadSeekCloseris
ReadAtSeekCloser. - fstest no longer depends on testify, derives every name from the seed,
hasConfig.Skipand many new contract checks (errors, closed file systems,
cancellation, overwrite semantics, moves into itself, content above 1 MiB,
WriteAborter, URI boundary and round trip). The Docker helpers moved to
internal/dockertest. s3fsusesfeature/s3/transfermanagerinstead of the deprecated
feature/s3/manager;smbfsuses the maintainedgithub.com/cloudsoda/go-smb2
fork (GO-2026-5051); dependencies are bumped (x/net, x/text, x/crypto,
x/sys, AWS SDK, jlaffaye/ftp v0.2.4, Dropbox SDK v6.6.2).- Copies never take over setuid, setgid and sticky bits.
CopyFile,
CopyRecursive, emulated moves, the overlay copy-up and
MemFileSystem.CopyFilegive the destination only the 9 permission bits of
the source; passpermto set special bits. A copy from a read-only file
system (uploads, archive entries,StdFileSystem) gets the owner write bit,
so an upload copies as 0644 instead of 0444.NewFileInfo(Local,
StdFileSystem, sftpfs, smbfs) reports the special bits. - Directory links in recursive walks.
ListDirRecursive(native and
emulated) never descends into a symbolic link to a directory, like
filepath.WalkDir: the link itself is passed to the callback with
IsSymlinktrue andIsDirfalse; a link at the start of the listing is
followed.CopyRecursiveand moves recreate a link to a directory as a
link with its verbatim target within one file system instance that
supports links. Between different instances, or if the destination can't
create links, they fail before writing anything with an error wrapping
errors.ErrUnsupported; links to files are copied as files. Copies never
write through a symbolic link below the destination root, a link where a
file or directory is to be written is an error wrappingos.ErrExist;
this assumes nobody else changes the destination during the copy. - XAttr errors.
XAttrCreateon an existing attribute wraps
os.ErrExist;XAttrReplaceandGetXAttr/RemoveXAttrof a missing
attribute wrapos.ErrNotExist(Local and MemFileSystem); fstest checks it. - Archive names.
fs.ZipandZipMemFilesreject names that escape
with.., names with a backslash and absolute names (the leading slash of
aMemFilename is dropped) with an error wrappingos.ErrInvalid, so every archive
they write unzips withUnzipToMemFiles;zipfs.Readerskips symbolic
links, devices and FIFOs liketarfs. - Root directories.
RemoveandRemoveAllof the root return an error
wrappingos.ErrInvalidin every file system, also for relative paths of
the root like"."in sftpfs and ftpfs, instead of deleting the whole
bucket, container or server tree in s3fs, azureblobfs, sftpfs and ftpfs and
callingos.RemoveAll("/")for the root of a local volume. - Paths. Only a
~at the start of the first part of a Local path means
the home directory, a directory named~is written./~; a SubFileSystem
stores relative link targets with..as paths of the parent; smbfs paths
and link targets containing\, and link targets with a drive letter, are
errors wrappingos.ErrInvalid;TempFilereturnsInvalidFilefor an extension with a
path separator;StdFSand SubFileSystems of Local apply theos.DirFS
name rules (Windows device names,\,:, NUL) to the local file system
only. - Same file under two names.
LocalFileSystem.Moverenames a file onto
its own directory entry under another spelling (case, Unicode
normalization) and moves a file with more than one hard link through a
temporary.gofs-move-*name, so it never removes the only link of a file;
moves through bind mounts, symbolic links to a parent or a SubFileSystem
onto the same file never copy and remove it, also through the local layers
of anOverlayFileSystem. Moving a symbolic link onto the file it points
to is an error wrappingos.ErrInvalid, likemvreports "are the same
file", in Local, Mem, sftpfs, smbfs and the move emulation;CopyFileof a
file onto itself through another path is a no-op.fs.Moveof a...