GithubHelp home page GithubHelp logo

rust-lang-deprecated / tempdir Goto Github PK

View Code? Open in Web Editor NEW
139.0 139.0 27.0 786 KB

Temporary directory management for Rust

Home Page: http://doc.rust-lang.org/tempdir

License: Apache License 2.0

Rust 100.00%

tempdir's People

Contributors

abonander avatar alex avatar alexcrichton avatar andersk avatar briansmith avatar brson avatar chills42 avatar cldfire avatar dtolnay avatar kodraus avatar opilar avatar r-52 avatar rfdonnelly avatar shepmaster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tempdir's Issues

Design question: why support just dirs and not files?

I'm curious about the reasons for focusing specifically on temp dirs and not temp files. Are there security benefits to always using a dir? Or simplicity/portability benefits? Asking out of historical interest more than anything else. (Apologies if this is an abuse of issues :) )

Deprecate the tempdir crate

In Stebalien/tempfile#33 we combined the tempdir and tempfile APIs, with the goal of using the tempfile crate as the source of temporary files and directories going forward.

I've gone through and review the open issues here (and basically just closed them all). I think the next step is to propose deprecating this repository and moving into rust-lang-deprecated, with a note in the readme that tempfile is the place to go for temporary directories going forward.

What do you all think? Is there anything else we should consider?

Support ramfs through type `RamDir`

I'm curious whether tempdir would be interested in adding a RamDir type if it were possible to make such a type.

tmpfs is:

tmpfs is a temporary filesystem that resides in memory and/or swap partition(s). Mounting directories as tmpfs can be an effective way of speeding up accesses to their files, or to ensure that their contents are automatically cleared upon reboot.

It looks like there is a (linux only) libmount that could be leveraged to do the job, although I would prefer using ramfs, as it is guaranteed to be in ram. I haven't looked at that crate, but ramfs could potentially be added there.

It's also at least theoretically possible to support windows, as a tool exists called ImDisk, but this issue is suggesting unix-only support through the tmpfs call (for now).

This issue is mostly to ask whether this feature would be supported by the project devs or whether a new crate should be made instead. Thanks!

Unnecessary Option in TempDir or panicky code

TempDir currently looks like this:

pub struct TempDir {
    path: Option<PathBuf>,
}

And functions rely on it being an Option, ex:

pub fn path(&self) -> &path::Path {
    self.path.as_ref().unwrap()
}
// and
pub fn into_path(mut self) -> PathBuf {
    self.path.take().unwrap()
}

These functions do not take into consideration that the path could be set to None.
Currently this is not a problem because fn new_in will never set it to None however many times it will retry to find a random folder name.
So, the result is either path(from TempDir) being set to Some(path) or the user receiving Err.
In this case, why not get rid of the Option and just set the TempDir { path: } directly to path and return Err otherwise?

If None is planned for feature use, than functions like path and into_path should probably return Option<&path::Path> and Option<PathBuf> instead of unwrapping for the user and panicking.

This of course will bump the library version.

option to keep a temporary directory after panic, for debugging purposes

Suppose that I have some code which works inside of a temp dir, and a bug is detected which causes it to panic. When this occurs, I would like to be able to go look at the temporary directory and inspect the files created leading up to the error. However, during the panic, it will invariably have unwound through the TempDir destructor, and so the directory is gone.

Currently the only real solution I have is to write all of my temp dir construction like this:

let tmp = TempDir::new("my-thing");
let tmp = tmp.path();

and then after a crash occurs, I find the line for the pertinent temp dir, change path to into_path, and then try to reproduce the crash. I don't think this strategy will scale very well.

Deref and Into

Did you consider implementing Deref<Target=Path> and Into<PathBuf> instead of the methods into_path() and path() ?

deprecate into_path(), rename persist()

Feature Request

This is a feature/API change request to rename into_path() to persist(), while deprecating into_path().

Reasoning

While I understand the logic behind calling it into_path() (since it "converts" the temporary directory into an "ordinary path"), into_path() actually performs an action from the programmers point of view, namely it removes the invariant that the temporary directory will be deleted on drop.

This is made even more confusing by the documentation, which says: "This destroys the TempDir without deleting the directory represented by the returned Path." -- from a lingual point of view it sounds like we are destroying the directory

Solution

/// Consumes the `TempDir` object without deleting the directory, 
/// returning the `PathBuf` where it is located.
///
/// The directory will no longer be automatically deleted.
fn persist(self) -> PathBuf { self.into_path() }

path to 1.0

Ive been going through our dependencies and I saw that this crate is pre-1.0 and also didn't have a tracking issue for getting there. I wanted to post this to see if there was a plan for getting to 1.0. Considering how few issues have been posted with this crate and how often it's used, I'd think it would be pretty close to a 1.0, so wanted to check in here to see what the maintainers think.

Publish New Version

This is just a request for a new version of tempdir to be published with the updated version of rand (from #40).

Move back to nursery

An RFC is required for deprecating nursery crates. There has been no RFC so this crate must be moved back to the nursery.

TempDir ignores errors in drop

Any reason why TempDir ignores errors when dropped?

I feel this is unsafe default behavior, as it could lead to a long-running process leaking temporary directories. To avoid this problem, a program must wrap TempDir and have the wrapper call TempDir::close in the wrapper's destructor—all to find out that an error occurred.

Here's an alternative. Suppose the TempDir destructor panicks on error instead of silently squashing it. This means a program's default behavior is to be notified of the error. If a program must prevent panicking—for whatever reason—then that program could do the wrapper thing and squash the error in the wrapper's destructor.

The alternative strategy is safer, as it requires action on the part of the programmer to ignore errors instead of requiring action on the part of the programmer to be notified of errors. In the case of TempDir's destructor, an error is probably a leak, the elimination of which is a big part of Rust's raison d'être.

Finalize conventions for `close`

There's no precedent in std for this, and there's been suggestion that the current signature is not correct (preferring &mut self to self).

Depends on broken version of rand

Tok:tempdir doug$ cargo test
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling libc v0.1.3
   Compiling log v0.2.5
   Compiling rand v0.1.4
/Users/doug/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.1.4/src/os.rs:154:43: 154:52 error: failed to resolve. Use of undeclared type or module `Path`
/Users/doug/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.1.4/src/os.rs:154             let reader = try!(File::open(&Path::new("/dev/urandom")));
                                                                                                                               ^~~~~~~~~
<std macros>:1:1: 6:57 note: in expansion of try!
/Users/doug/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.1.4/src/os.rs:154:26: 154:71 note: expansion site
/Users/doug/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.1.4/src/os.rs:154:43: 154:52 error: unresolved name `Path::new`
/Users/doug/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.1.4/src/os.rs:154             let reader = try!(File::open(&Path::new("/dev/urandom")));
                                                                                                                               ^~~~~~~~~
<std macros>:1:1: 6:57 note: in expansion of try!
/Users/doug/.cargo/registry/src/github.com-1ecc6299db9ec823/rand-0.1.4/src/os.rs:154:26: 154:71 note: expansion site
error: aborting due to 2 previous errors
Could not compile `rand`.

Fix is trivially to use https://github.com/rust-lang/rand, but there doesn't seem to be a working version of rand on crates.io.

(Not)Equivalent of dangling pointer dereferencing when calling `path` after `into_path`

I was just looking through the code("looking for inspiration") and observed a bug that is the equivalent of dangling pointers but with Rust Options(of course, no memory corruption).
When calling into_path, path will be replaced with None - then -> if somebody calls the path function, the application will panic(because it unwraps for the user - which would be the equivalent of dereferencing a dangling pointer).
I think it's better to break the API(v0.4) and make this function return an Option<&path::Path>, or maybe some other option(solution).

Support randomly-named directories

When writing tests that need a working directly I've used randomly-named directories a lot. The Python equivalent of tempdir does that by default. I was thinking of the addition of tempdir::new_unique() that would generate a new unique temporary directory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.