google / google/renameio

Support of specific tmpDir with os.Root

Open
#46 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
679
Forks
34
PR merge metrics
No merged PRs in 30d

Description

Hi!

thanks for adding support for `os.Root()` here @stapelberg!

I would just have a small feature request:

- When using `WithRoot(r)` it is assumed by `renameio/v2` that tmp files should be in the top-level directory of `r`.
- In my case I would like to have them in a folder like `.sesam/tmp` and the destination after `CloseAtomicallyReplace()` would be somewhere other under `r`.
- Opening `.sesam/tmp` as own root does not help, as I can't reach the destination path then.
- The reason I want a dedicated `tmp` folder is that it can be cleared completely easier, opposed to several tmp files lying around (also that `.sesam/tmp` dir is automatically git-ignored).

Volunteering to add a PR, just thought I'd do a ticket first to see if that would be appreciated.
If yes, would that be a new option like `WithRootTempDir()`? Or would we honor `WithTempDir()` in that case by doing something like:

```go
tmpname = "." + filepath.Base(cfg.path)
if cfg.dir != "" {
tmpname = filepath.Join(cfg.dir, tmpname)
}
tmpname, f, err = openTempFileRoot(cfg.root, tmpname, cfg.createPerm)
```

(referenced line is [here](https://github.com/google/renameio/blob/v2.0.2/tempfile.go#L255))

Contributor guide

Open the contributing guide

Research direction

Start in tempfile.go around the referenced openTempFileRoot call and trace how WithRoot and WithTempDir populate the configuration. Compare the proposed root-relative temporary directory behavior with CloseAtomicallyReplace’s destination handling. Done means temporary files can be placed under a configured directory within the root while replacement still reaches the requested destination, with coverage for the chosen API behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.