Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise overloaded temp methods #150

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Revise overloaded temp methods #150

wants to merge 3 commits into from

Conversation

rofinn
Copy link
Owner

@rofinn rofinn commented Nov 17, 2021

To support new 1.3+ kwargs (e.g., prefix, cleanup).

NOTE: This should be a breaking release as we now require tempdir to be define for all path types.

Closes #141

@codecov
Copy link

codecov bot commented Nov 17, 2021

Codecov Report

Merging #150 (8b90a94) into master (eb9895e) will decrease coverage by 0.16%.
The diff coverage is 80.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #150      +/-   ##
==========================================
- Coverage   91.84%   91.68%   -0.17%     
==========================================
  Files          12       12              
  Lines        1190     1202      +12     
==========================================
+ Hits         1093     1102       +9     
- Misses         97      100       +3     
Impacted Files Coverage Δ
src/system.jl 90.32% <75.00%> (-2.10%) ⬇️
src/path.jl 88.05% <84.61%> (+0.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb9895e...8b90a94. Read the comment docs.

function Base.download(url::AbstractString, localfile::P) where P <: AbstractPath
mktemp(P) do fp, io
function Base.download(url::AbstractString, localfile::AbstractPath)
mktmp() do fp, io
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mktemp(P) previously returned a SystemPath by default. We've changed this, so we've made this explicit to avoid infinite recursion on the download call below.


Base.mktempdir(fn::Function, P::Type{<:AbstractPath}) = mktempdir(fn, tempdir(P))
mktmpdir(fn::Function) = mktempdir(fn, SystemPath)
Base.tempname(P::Type{<:AbstractPath}; kwargs...) = tempname(tempdir(P); kwargs...)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default behaviour for tempname now calls tempdir(P), so we require that all new path types define that method for their specific type.

Base.mktempdir(P::Type{<:AbstractPath}; kwargs...) = mktempdir(tempdir(P); kwargs...)
Base.mktempdir(fn::Function, P::Type{<:AbstractPath}; kwargs...) = mktempdir(fn, tempdir(P); kwargs...)

function Base.tempname(parent::AbstractPath; prefix="jl_", cleanup=true)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix was also added in 1.2 (though not as consistently).


function Base.tempname(parent::AbstractPath; prefix="jl_", cleanup=true)
isdir(parent) || throw(ArgumentError("$(repr(parent)) is not a directory"))
fp = parent / string(prefix, uuid1())
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to uuid1 over uuid4. For older releases of Julia, these function depended on the GLOBAL_RNG and could in theory result in collisions if folks were resetting while generating temp files and directories.

function temp_cleanup(fp::AbstractPath)
atexit() do
# Might not work in all cases, but default to recursively deleting the path on exit
rm(fp; force=true, recursive=true)
Copy link
Owner Author

@rofinn rofinn Nov 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the specific suggestion made in #141. It might not always work, but it seems better than nothing?

@@ -113,8 +113,8 @@ function isexecutable(fp::SystemPath)
return (
isexecutable(s.mode, :ALL) ||
isexecutable(s.mode, :OTHER) ||
( usr.uid == s.user.uid && isexecutable(s.mode, :USER) ) ||
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My editor fixed some formatting issues from now till my next commend.

function Base.mktemp(parent::T) where T<:SystemPath
fp, io = mktemp(string(parent))

Base.tempdir(::Type{<:SystemPath}) = Path(tempdir())
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the SystemPath specific defaults to the system.jl file.

@@ -70,5 +70,6 @@ Base.read(fp::TestPath) = read(test2posix(fp))
Base.write(fp::TestPath, x) = write(test2posix(fp), x)
Base.chown(fp::TestPath, args...; kwargs...) = chown(test2posix(fp), args...; kwargs...)
Base.chmod(fp::TestPath, args...; kwargs...) = chmod(test2posix(fp), args...; kwargs...)
Base.tempdir(::Type{TestPath}) = posix2test(tempdir(PosixPath))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of needing to add a Base.tempdir overload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mktempdir should support cleanup=true by default
1 participant