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

Fix #9932 #11024

Merged
merged 1 commit into from
May 5, 2015
Merged

Fix #9932 #11024

merged 1 commit into from
May 5, 2015

Conversation

mikewl
Copy link
Contributor

@mikewl mikewl commented Apr 27, 2015

This fixes #9932 by first creating a TEMP directory to clone into. Once the clone is complete the contents of TEMP are copied into METADATA.

I am not sure if the comments are excessive. Will prune if necessary.

#Or temp was not fully deleted
#Remove METADATA as well and reinit rather
if isdir(metadata_dir)
rm(metadata_dir, recursive=true)
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing an end here, and please use 4-space indent. I like the comments though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually - how did that compile?! Fixing now.

Copy link
Contributor

Choose a reason for hiding this comment

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

it didn't compile, at least not on travis

@tkelman tkelman added the domain:packages Package management and loading label Apr 27, 2015
@tkelman
Copy link
Contributor

tkelman commented Apr 27, 2015

Good idea.

@@ -54,12 +64,17 @@ function init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRA
close(io)
end
end
#Copy TEMP to METADATA and remove TEMP
Base.cp(temp_dir, metadata_dir)
rm(temp_dir, recursive=true)
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason not to do mv here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

None, other than I forgot it existed!

@mikewl
Copy link
Contributor Author

mikewl commented Apr 27, 2015

Crap. I clearly am not good with git yet >_<
Not sure why my indentation keeps on going off, indent is set to 4 and I keep on running auto indent on it.

Sorry about the nonsense!

@tkelman
Copy link
Contributor

tkelman commented Apr 27, 2015

and I keep on running auto indent on it.

Might be a bug with the Julia plugin for whatever editor you're using.

@mikewl
Copy link
Contributor Author

mikewl commented Apr 27, 2015

I fixed it manually and cleaned it all up, really sorry about the crap >_<

@tkelman
Copy link
Contributor

tkelman commented Apr 27, 2015

No worries, git can be really frustrating as you first get used to doing more complicated things with it.

I think lines 62 and 63 are still under-indented. Would be nice if we had an auto-formatter.

@mikewl
Copy link
Contributor Author

mikewl commented Apr 27, 2015

As you commented that I fixed it.

Seeing as that is my 2nd biggest issue (not knowing how to rebase properly would be no.1 - time to make sure I can do that right) where can I look how to do that? Can it be done as a github plugin?

@tkelman
Copy link
Contributor

tkelman commented Apr 27, 2015

You got 65-67, but not 62-63, from what I can see.

I do wonder how much infrastructure the github web editor has in common with atom, whether you can make atom settings for smart indenting apply within the web editor...

@tkelman
Copy link
Contributor

tkelman commented Apr 27, 2015

Something a little like https://github.com/google/yapf or clang-format that we could just run automatically and not have to think about it would be ideal, but I don't know if anyone has come up with anything standalone for Julia that isn't just leveraging existing text editors' plugin infrastructure.

@mikewl
Copy link
Contributor Author

mikewl commented Apr 27, 2015

I may try and do something similar to YAPF! I think I edited and committed those lines now 4 times with atom only actually saving them after I closed atom. I was quite annoyed.

Does Julia have a more comprehensive guideline for Julia code other than the one in CONTRIBUTING.MD? Fixing indentation would be quite easy I think, as well as trailing whitespace.

It should probably be done in Julia, then it could be a package which could also emit an executable once the work there is completed.

Any name that would be preferred? I should have a chance to get to starting this tonight. Will ask for comments once I get to a working state.

@tkelman
Copy link
Contributor

tkelman commented Apr 27, 2015

I don't think we do have a coherent code style guideline beyond CONTRIBUTING.md. Take a look at what the different editor plugins do, maybe bug the authors of them and/or solicit julia-users for some thoughts (and name suggestions). https://github.com/jakebolewski/JuliaParser.jl will probably also be very useful to verify that a formatter only changes appearance and not meaning.

@tkelman
Copy link
Contributor

tkelman commented Apr 27, 2015

Oh dear. Back to the subject of this PR, it looks like it's failing the pkg test on Travis (and I can reproduce that with a local checkout of this branch). Need to get to the bottom of that... are you working from a source build of Julia?

@mikewl
Copy link
Contributor Author

mikewl commented Apr 27, 2015

I am working on a source build of Julia yes. Internet is being painfully slow right now unfortunately.

Found the issue. Hidden folders are not copied so the .git folder is never copied over.

I think I am going to leave this as is and will have to open up a second PR modifying mv and cp to include a hidden option. I will have to make new tests for that won't I?

@mikewl mikewl changed the title Fix #9932 WIP: Fix #9932 Apr 27, 2015
@tkelman
Copy link
Contributor

tkelman commented Apr 27, 2015

Interesting. Yes, tests for new functionality are always good. @peter1000 was just recently working on recursive cp, but I don't know whether the tests included any hidden subfolders.

@peter1000
Copy link

If you want I can look into the cp hidden folder issue? Just asking to not double the effort.

@peter1000
Copy link

Seems if I do

julia> cp("Docile.jl", "test")

test contains also the .git folder

julia> versioninfo()
Julia Version 0.4.0-dev+4524
Commit 982c60a (2015-04-27 00:18 UTC)
Platform Info:
  System: Linux (x86_64-unknown-linux-gnu)
  CPU: Intel(R) Core(TM) i3-2310M CPU @ 2.10GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

@tkelman
Copy link
Contributor

tkelman commented Apr 27, 2015

though we are using mv here so maybe the underlying problem is in sendfile

@peter1000
Copy link

seems to work too

mv("DocOpt.jl", "test2")

"test2" has the .git folder

not sure what happens if there are wrong permissions or files are currently open by an other application: just a thought

@mikewl
Copy link
Contributor Author

mikewl commented Apr 27, 2015

Hmmm. Think I am going to do a make clean and start from there again.

Sorry for bugging you @peter1000.

I am quite confused as to how the error is being thrown. Built it on windows with everything copying right now. Same error as before though:

fatal: Not a git repository (or any of the parent directories): .git
ERROR: failed process: Process(setenv(`git rev-parse --git-dir`; dir="/home/michaelwl/.julia/v0.4/METADATA"), ProcessExited(128)) [128]
 in readbytes at process.jl:458
 in dir at pkg/git.jl:10
 in git at pkg/git.jl:16
 in set_remote_url at pkg/git.jl:106
 in init at pkg/dir.jl:46
 in init at pkg.jl:17

@peter1000
Copy link

hi Mike43110,

no problem. I'm on linux and can't help you with Windows.

What I could do is copy you commit and try it out here - just not sure how to test this if it works. If you shortly instruct me I can do that for you.

@mikewl
Copy link
Contributor Author

mikewl commented Apr 27, 2015

Don't worry, I was sorely mistaken it seems! mv and cp are fine I am just utterly, utterly blind.
New to working on Linux so unfortunately there I am a complete idiot.

Thanks for the offer though! Lesson learned: even if it seems unrelated, run the test suite anyway!
Lesson 2: Read it at least 5 times, I seem to miss the things I am looking for.

I will fix this. My internet has bombed out multiple times just testing this, making this fix quite important for me! (Wonderful South Africa)

@mikewl
Copy link
Contributor Author

mikewl commented Apr 27, 2015

All green at last.

Thanks guys for putting up with me, I checked practically everything I could before stumbling onto the issue that git clone made a folder METADATA inside the temp folder while it cloned directly into metadata_dir. I feel quite stupid now!

But in the end, green ticks at last and now a failed init which happens oh so often won't be as much of a pain anymore!

@mikewl mikewl changed the title WIP: Fix #9932 Fix #9932 Apr 27, 2015
#Move TEMP to METADATA
Base.mv(joinpath(temp_dir,"METADATA"), metadata_dir)
Base.mv(joinpath(temp_dir,"REQUIRE"), joinpath(metadata_dir,"REQUIRE"))
Base.mv(joinpath(temp_dir,"META_BRANCH"), joinpath(metadata_dir,"META_BRANCH"))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think REQUIRE and META_BRANCH should be moved to joinpath(dir, ...) instead of metadata_dir ?

@StefanKarpinski can you take a look at this?

@mikewl
Copy link
Contributor Author

mikewl commented Apr 28, 2015

Thanks for the comments @tkelman, those files were in the incorrect positions.

I fixed them and added tests to check their positions.

@mikewl
Copy link
Contributor Author

mikewl commented Apr 28, 2015

Looks like I will need to test this on Ubuntu again instead of Windows.

Had a small error in the test. Windows should have failed as well.
@test isfile(joinpath(Pkg.dir(),"METADATA_BRANCH")) should have failed on windows and Linux.

@mikewl
Copy link
Contributor Author

mikewl commented Apr 28, 2015

All is green again. I am a little concerned that windows passed initially as it shouldn't have. Is there a bug with isfile?

@tkelman
Copy link
Contributor

tkelman commented Apr 29, 2015

We don't run the pkg tests on appveyor right now.

@tkelman
Copy link
Contributor

tkelman commented Apr 29, 2015

Would be good to squash so we don't introduce a commit that is known to fail tests in the history of master, for the sake of future use of git bisect.

I think this could be merged after squashing, but would really like to get @StefanKarpinski's buy-in on anything Pkg-related.

@mikewl
Copy link
Contributor Author

mikewl commented Apr 29, 2015

Aah! That clears up that piece of confusion thanks.

Understand that you want his input first completely. While he is here:
Would it be alright to try and tackle #7005? I noticed after changing my clone URL for Julia to https instead of git I manage to get a much better download speed both on windows and linux. So I am wondering if adding a flag to the Pkg related stuff to tell it to use https instead of git would provide a similar effect for Julia on my wonderfully terrible internet.

metadata_dir = joinpath(dir, "METADATA")
#Check if TEMP dir exists from previous failed init
if isdir(temp_dir)
Copy link

Choose a reason for hiding this comment

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

Just a thought, why not use base.mktempdir() and then you won't need to do this test.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

it's also best not to call rm when you can avoid it, since the user would be most unhappy to lose a working directory they happened to call TEMP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove that and use Base.mktempdir()
There is a potential for a failed init() to cause the subsequent tests to fail because of an unclean directory - Pkg.status() reported the TEMP folder which would cause the test @test isempty(Pkg.installed()) to fail.
Though if I clone directly to the tmpdir instead of to the package location initially there won't be any issues!

@mikewl
Copy link
Contributor Author

mikewl commented Apr 29, 2015

current commit is just to have a place to fallback to.
Should probably add [ci skip] until its sorted. Internet is a bit spotty at the moment again making testing this a pain!

Ok! Internet working right so I could test and it all passes locally at the latest commit.

Will check if it goes green then will rebase.

Added Tests for REQUIRE and META_BRANCH existence
@tkelman
Copy link
Contributor

tkelman commented Apr 30, 2015

Let me run the pkg test on this locally just to make sure there isn't anything strange with mktempdir on Windows.

Would it be alright to try and tackle #7005? I noticed after changing my clone URL for Julia to https instead of git I manage to get a much better download speed both on windows and linux. So I am wondering if adding a flag to the Pkg related stuff to tell it to use https instead of git would provide a similar effect for Julia on my wonderfully terrible internet.

Not within the same PR, but it is a little unfortunate that nothing has come of that yet despite being bumped a few weeks ago. As a separate PR, moving towards doing more things over https (probably just by default, for security's sake) would be a good direction I think.

@tkelman
Copy link
Contributor

tkelman commented Apr 30, 2015

pkg test works okay on windows at mikewl@5709b35

@mikewl
Copy link
Contributor Author

mikewl commented Apr 30, 2015

I wonder if doing it in a minimally invasive way won't be good (for #7005).

splitmeta = split(meta,":")
    if !usehttps
        splitmeta[1] = "git"
    else
        splitmeta[1] = "https"
    end
    newmeta = ""
    for pos = 1:length(splitmeta) - 1
        newmeta = newmeta * splitmeta[pos] * ":"
    end
    newmeta = newmeta * splitmeta[end]

This can be used to change the url to https without needing to alter the METADATA repo.
I was thinking this can be placed as a function in pkg.jl or where appropriate so that depending on the flag usehttps will direct the url to wherever desired.

I tested this on init(). It works and the url in .git/config is https when the flag is set.
It should use the protocol chosen every time as the stored url isn't what is used but the transformed one. So using https initially doesn't mean you can't use the git protocol if desired.

Would this be fine for an initial change? It just allows the desired url to be selected. I need to find a proxy to test it through still.

@tkelman
Copy link
Contributor

tkelman commented Apr 30, 2015

I think a regex might be a more efficient way of doing that string operation, but opening an initial proof-of-concept pr in that direction sounds like a good idea to me. Could comment on #7005 after opening to solicit feedback from people who know more about these things than I do.

@mikewl
Copy link
Contributor Author

mikewl commented Apr 30, 2015

I did a regex initially then I realised that urls like "git://.../httpsServer.jl" may get affected. Using the array split ensures only the initial value is altered. Though I have minimal regex experience!

I am busy working on that and the formatter anyway. Worst case the PR gets rejected with a request to go in a different direction!

Thanks for the assistance though, very much appreciated.

@pao
Copy link
Member

pao commented Apr 30, 2015

@Mike43110 The regex character ^, as the first character of an expression, anchors to the beginning of the string.

@tkelman
Copy link
Contributor

tkelman commented May 2, 2015

Bump @StefanKarpinski can you take a look?

@tkelman
Copy link
Contributor

tkelman commented May 5, 2015

I'm going to merge this, since it seems like a step in the right direction and getting reviewers for PR's has apparently become extremely difficult lately.

If we find any unforeseen consequences or problems with this we can always revert it.

tkelman added a commit that referenced this pull request May 5, 2015
@tkelman tkelman merged commit 1df9c1a into JuliaLang:master May 5, 2015
@StefanKarpinski
Copy link
Sponsor Member

Sorry for the lack of review. This seems like a good approach and I'm sure we'll hear about it if it's broken.

@ScottPJones
Copy link
Contributor

@StefanKarpinski If you could also please review the documentation additions that you suggested (because of my surprise issues with coming from C/C++), I'd appreciate it! ;-) #11081 -> #11099

@kmsquire
Copy link
Member

kmsquire commented May 5, 2015

@ScottPJones, it's generally better to bump the relevant issues with @StefanKarpinski (or whomever's attention you want) than to add to a non-related issue. Cheers!

@tkelman
Copy link
Contributor

tkelman commented May 5, 2015

And general-purpose documentation improvements can usually be reviewed by a much larger number of people than specific details about Pkg, or compiler internals, or linear algebra, what have you, which tend to have different sets of informal "code owners."

Base.mv(joinpath(temp_dir,"METADATA"), metadata_dir)
Base.mv(joinpath(temp_dir,"REQUIRE"), joinpath(dir,"REQUIRE"))
Base.mv(joinpath(temp_dir,"META_BRANCH"), joinpath(dir,"META_BRANCH"))
rm(temp_dir)
Copy link
Member

Choose a reason for hiding this comment

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

why is this not rm(temp_dir, recursive=true)?

Copy link
Contributor

Choose a reason for hiding this comment

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

don't think it has to be since there shouldn't be anything left in it at this point, but maybe more defensive that way

Copy link
Member

Choose a reason for hiding this comment

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

Arg sorry for the noise, it is moving the directories not copying them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jakebolewski If the directory is not empty it then will error.
I had it the other way initially but thought that if some other change comes around which isn't accounted for in this then it will error.

I am not too sure whether this is a good thing though. It means if somebody adds an extra item to Pkg.init() it needs to be explicitly handled whereas if I had moved temp_dir to dir instead of each item individually that wouldn't have been a problem.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

It's better for that not to be a silent error, but it seems like this is kind of an unfortunately brittle arrangement.

Copy link
Contributor

Choose a reason for hiding this comment

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

It wouldn't be silent, would it? I'd think make test-pkg would show the error pretty quickly. If dir already happens to exist then I don't think it would work to move temp_dir to dir. I don't think we have a force kwarg for mv.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Right, the current behavior is better since it would fail if this directory weren't empty, so I guess we're ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without using -force which isn't available there is the option of removing the specific version directory completely though that also seems like it could have unintended consequences as well.

@mikewl mikewl deleted the fix_9932 branch May 5, 2015 15:28
@peter1000
Copy link

julia could add the kwarg: remove_destination::Bool=false to mv to be in line with cp

cp(src::AbstractString, dst::AbstractString; remove_destination::Bool=false, follow_symlinks::Bool=false)

If that is wanted I could do it.

@StefanKarpinski
Copy link
Sponsor Member

Yes please, @peter1000!

@peter1000
Copy link

Ok probably tomorrow with docs and test case.

@mikewl
Copy link
Contributor Author

mikewl commented May 6, 2015

Haunts @peter1000

@peter1000
Copy link

According to my reading: the current implementation of mv is not supposed to work on directories even the doc say: Move a file from src to dst

see related issue I opend: #11145

mbauman pushed a commit to mbauman/julia that referenced this pull request Jun 6, 2015
based on a comment by @tkelman
JuliaLang#11024 (comment)

I would like to add some tests for hidden folders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:packages Package management and loading
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pkg cannot recover from corrupted METADATA
10 participants