aboutsummaryrefslogtreecommitdiff
path: root/lib/memfs
AgeCommit message (Collapse)Author
3 dayslib/memfs: fix due to changes on [text/diff] packageShulhan
10 daysall: apply go fixShulhan
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2025-01-26lib/memfs: return nil on AddChild if path is not includedShulhan
Checking if child is nil is impossible here, because the AddChild create and return new child.
2025-01-23all: use for-range with numericShulhan
Go 1.22 now support for-range on numeric value.
2025-01-23all: replace "interface{}" with "any"Shulhan
2025-01-22lib/http: always refresh a directory on GET requestShulhan
On server with TryDirect is true, any GET request to a directory should always rescan the content and the generate the new index.html. While at it, return the generated time in UTC instead of local time.
2025-01-06lib/memfs: remove GoEmbed test that generate dynamic timesShulhan
The GoEmbed test that write Go embedded code into "internal/test/embed/" may create unnecessary changes when the test run on new clone of this repository, or when we run "go test" again on that package after rebasing.
2024-12-29all: merge package "lib/ints" and "lib/ints64" into "slices"Shulhan
Now that Go has type parameter, we can use it to use the same function that accept different types for working with slice of int, int64.
2024-12-28lib/bytes: split the hexdump related functions to separate packageShulhan
Package hexdump implements reading and writing bytes from and into hexadecimal number. It support parsing output from hexdump(1) tool.
2024-12-28lib/memfs: move the old Watcher and DirWatcher to watchfsShulhan
The watchfs package now contains the original, v1, of the Watcher and DirWatcher types. This changes require exporting method [memfs.MemFS.UpdateContent].
2024-12-28lib/memfs: refactoring Watch to use "watchfs/v2"Shulhan
2024-12-03lib/memfs: move compiled regex to their optionsShulhan
This changes move the following fields and methods from MemFS, * incRE and excRE fields to Options, * isIncluded and isExclude methods to Options, * watchRE field to WatchOptions, * isWatched method to WatchOptions. The reason is to allow other type that use Options or WatchOptions to use isIncluded, isExclude, or isWatched methods.
2024-09-04all: fix various linter warningsShulhan
While at it, temporary disable gosec due to excessive report for G115, which may be true, but may also break the current working program. We should alter and fix once we can test and make sure that it does not breaks.
2024-08-09lib/memfs: document the comparison with "go:embed" directiveShulhan
Compared it with "go:embed", the memfs package is more flexible and portable. Currently, we found three disadvantages of using "go:embed", #1 - The "go:embed" only works if files or directory to be embedded is in the same parent directory. #2 - Accessing the embedded file require the original path. #3 - No development mode.
2024-08-03lib/memfs: another fix for refreshShulhan
In previous commit we use wrong condition when handling directory "." as Root.
2024-07-22lib/memfs: sanitize the Root directory to fix refreshShulhan
In [MemFS.refresh], if the requested url is "/file1" and [Options.Root] is ".", the path during refresh become "file1" and if passed to [filepath.Dir] it will return ".". This cause the loop on refresh never end because there is no PathNodes equal with ".".
2024-04-10lib/memfs: set embed file mode to print as octalShulhan
Using octal in mode make the code more readable, for example mode with permission "0o644" much more readable than 420.
2024-03-21lib/memfs: trim trailing slash ("/") in the path of Get methodShulhan
The MemFS always store directory without slash. If caller request a directory node with slash, it will always return nil.
2024-03-09all: reformat all files with goimportsShulhan
2024-03-09lib: move package "net/html" to "lib/html"Shulhan
Putting "html" under "net" package make no sense. Another reason is to make the package flat under "lib/" directory.
2024-03-06all: conform with linter gosec, ineffasign, and makezeroShulhan
Some of warnings from those linter are false positives, so we just annotated them.
2024-03-05lib/memfs: remove deprecated Merge functionShulhan
The Merge function has been replaced with [memfs.MemFS.Merge] for better API.
2024-03-05all: comply with linter recommendations #3Shulhan
For HTTP server that use TLS, set the minimum TLS version and ReadHeaderTimeout to mitigate slowloris attack. For HTTP client or server that parameterize the use of InsecureSkipVerify, annotate the line with "nolint:gosec" to allow the code pass the check. Library that still use sha1, in example in DKIM and TOTP, skip the warnings by annotating the line with "nolint:gosec". A pointer variable now allocated their address before assigning its value. Any error that returned now wrapped using "%w". Also, replace error checking using [errors.Is] or [errors.As] instead of using equal or not-equal operators. In "lib/http", replace any usage of "math/rand" with "crypto/rand". Any call of [math/big.Rat.SetString] now annotated with "nolint:gosec" since its false positive, the issue has been fixed in Go >= 1.17.7. Any switch case that does not cover the rest of the possible values now handled by adding the cases or by replacing the "default" case with the rest of values.
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2024-03-05all: comply with linter recommendations #1Shulhan
Instead of annotating the lines that caught by linters, fix it to comply with the recommendations. This causes several breaking changes, especially related to naming, * api/slack: [Message.IconUrl] become [Message.IconURL] * lib/dns: DefaultSoaMinumumTtl become DefaultSoaMinimumTTL * lib/email: [Message.SetBodyHtml] become [Message.SetBodyHTML] * lib/http: [Client.GenerateHttpRequest] become [Client.GenerateHTTPRequest] * lib/http: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/http: [EndpointRequest.HttpWriter] become [EndpointRequest.HTTPWriter] * lib/http: [EndpointRequest.HttpRequest] become [EndpointRequest.HTTPRequest] * lib/http: [ServerOptions.EnableIndexHtml] become [ServerOptions.EnableIndexHTML] * lib/http: [SSEConn.HttpRequest] become [SSEConn.HTTPRequest] * lib/smtp: [ClientOptions.ServerUrl] become [ClientOptions.ServerURL] * lib/ssh/sftp: [FileAttrs.SetUid] become [FileAttrs.SetUID] * lib/ssh/sftp: [FileAttrs.Uid] become [FileAttrs.UID]
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2024-02-04lib/memfs: protect internal [DirWatcher.fileWatcher] with mutexShulhan
This is to fix several flaky tests on ExampleDirWatcher [1]. [1] https://github.com/shuLhan/share/actions/runs/7765975142 [2] https://github.com/shuLhan/share/actions/runs/7672754239
2024-02-03lib/memfs: fix flaky test on [Memfs.Get] with refreshShulhan
The test is flaky because we use range over map of [tdata.Input]. Since range over map will return random key, there is possibility that the first test is writing "/dir-a/dir-b/file2" not "/dir-a/dir-b/file".
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-12-09lib/memfs: add parameter withContent to [Node.JSON]Shulhan
If the parameter withContent is true, which is default in MarshalJSON, then all of the node content will be included in JSON output. This also changes the parameter withoutModTime to withModTime because working with negation make code not easy to read.
2023-11-22lib/memfs: add sub file systemShulhan
This implemented simplified version of merging multiple MemFS instances. The sub file system (subfs) can be added to the parent MemFS instance by calling new method "Merge". parent.Merge(other *MemfS) When Get method called, each subfs will be evaluated in order of Merge called. This deprecated the function Merge.
2023-11-21lib/memfs: check for file not exist in scanDir and updateDirShulhan
Another error for handling fs.ErrNotExist when scanning directory which is may caused by broken symlink.
2023-11-15lib/memfs: check for empty path on GetShulhan
2023-11-14lib/memfs: improve the refresh methodShulhan
Instead of refreshing from the Root, find the directory that closes to the requested path. While at it, simplify the returned error.
2023-11-14lib/memfs: add method JSON to NodeShulhan
The JSON method encode the Node into JSON. This method provides an alternative to MarshalJSON with granular options, depth and withoutModTime. The depth set the level of childs to be encoded. The depth=0 only encode the Root Node itself (with its childs), depth=1 encode the Root node and its subdirectories, and so on. If withoutModTime is set to true, all of the node ModTime will not be included in output.
2023-11-14lib/memfs: simplify error on GetShulhan
If the path does not exist it will return long string, Get: /path/relative/to/root: stat /ab/so/lu/te/path no such file or directory We simplify it to Get "/path/relative/to/root": file does not exist
2023-11-14lib/memfs: increase delay on DirWatcher exampleShulhan
We try with 100ms but sometimes it stuck on the first <-dw.C.
2023-11-14lib/memfs: add option to pack JSON without ModTimeShulhan
2023-11-08lib/memfs: split handling deleted directory and file on DirWatcherShulhan
When a directory being deleted we recursively unmap all its sub directory. When a file being deleted we stop its watcher.
2023-11-08lib/memfs: stop all Watcher spawn by DirWatcherShulhan
Previously, the Watcher goroutine will stopped only if the file is being deleted. If the DirWatcher stopped manually, by calling Stop method, the Watcher goroutine will still running in the background. This changes record all spawned Watcher and stop it when files inside a deleted directory or when Stop called.
2023-11-08lib/memfs: use second channel to stop goroutine in WatcherShulhan
Calling Ticker.Stop does not stop the "for-range", as shown in this test: var ( delay = 100 * time.Millisecond tick = time.NewTicker(delay) ) go func() { time.Sleep(2 * delay) tick.Stop() }() for range tick.C { t.Logf(`ticking`) } t.Logf(`ticker stopped`) the "ticker stopped" will never be printed. This will cause the Watcher will leak goroutine.
2023-11-08lib/memfs: do not return when mode changes in Node UpdateShulhan
If the FileInfo for Mode changes, update its value and keep going to check for modification time or size. While at it, update Readdir comment to reflect the actual FileInfo being returned.
2023-11-08lib/memfs: remove embedding os.FileInfo and http.FileShulhan
The original idea of embedding those interface is to guard the Node implementation to always follow all methods in the os.FileInfo and http.File, in case there is additional methods in the future. But, embedding interfaces make the struct store it as field "FileInfo" and File with "<nil>" values, which add storage cost to Node.
2023-11-08lib/memfs: remove mocking os.StatShulhan
The original idea of mocking the os.Stat to allow running test without adding Sleep, but this cause our tests a little bit flaky.
2023-11-08lib/memfs: refactoring, simplify DirWatcher logicShulhan
In this changes, we simplify re-scanning the directory content. Instead of looping on node Childs to detect new or delete files, use map to store previous Childs first. If node path exist in map then add it again as child, otherwise delete it.
2023-11-07lib/memfs: add test for DirWatcher with symlink to fileShulhan
2023-11-05lib/memfs: re-scan directory content on Node's UpdateShulhan
Previously, only node content get updated. In case in the MemFS, user set "Options.TryDirect" to true, the directory content should be updated too on "MemFS.Get".
2023-11-05lib/memfs: include empty directoryShulhan
Even thought empty directory does not contains file, from the parent node _it is_ part of their content. Also, there is a use case where memfs use as virtual file system (VFS), as a layer with file system, where user can view list of directory, create a directory or file on the fly. If we skip scanning empty directory, that directory will not be visible.
2023-10-29lib/memfs: call the Init method in the embedded fileShulhan
By calling the Init method, the regular expression for include and excludes is initialized, which allow using any method of MemFS instance later, for example the Watch method. While at it, fix the fields alignment in template code format.