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 #8225 os.isHidden was buggy on posix #8315

Merged
merged 2 commits into from
Oct 14, 2018
Merged

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Jul 14, 2018

/cc @dom96
fixes #8225
fixed bugs on posix:

  • isHidden shouldn't care whether file exists or not (purely string operation)
  • now works for dirs, not just files so that isHidden(".git") now returns true
  • there was also a bug where .ab.txt was considered not hidden (even if it existed!) because of the weird condition fileName[3] != '.'
    EDIT: use the new lastPathPart proc so that isHidden(".git/") now returns true as well

@timotheecour timotheecour force-pushed the pr_isHidden branch 3 times, most recently from 688fc2d to 47f6193 Compare July 14, 2018 08:05
@Varriount
Copy link
Contributor

With regards to the "this should purely be a string operation", this makes the behavior of the function subtly different across Linux and Windows. It means that on Windows, the function can only be called on existing files, while on Linux it can be called on all possible file names.

@Varriount Varriount requested review from dom96 and Varriount July 14, 2018 10:43
@timotheecour
Copy link
Member Author

timotheecour commented Jul 14, 2018

well I had suggested #8225 (comment) which would've mostly avoided that issue via a cross platform isDotPath (called by os.isHidden on posix):

ospaths.isDotPath => checks only for paths, works cross platform
os.isHidden => calls ospaths.isDotPath on posix, calls windows specific on windows (ie, same as my top level recommendation)

but @dom96 suggested not to:

Don't add any new procs. Just implement your proposal.

That just reflects OS differences; can't completely hide differences here

lib/pure/os.nim Outdated
## NOTE: on OSX, in addition to the "dotfile" behaviour, existing paths with the
## "Invisible" attribute are hidden in Finder, although not in ls
## NOTE: the behavior of certain corner cases (see examples) ".foo/" is
## unspecified, subject to change (can be avoided using `normalizePath`)
Copy link
Contributor

Choose a reason for hiding this comment

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

When writing docs, please check what they look like with nim doc. Currently this is all going to be one huge paragraph, and therefore hard to read. Add empty ## to separate this and use bold instead of ALLCAPS to emphasise.

Copy link
Member Author

@timotheecour timotheecour Jul 14, 2018

Choose a reason for hiding this comment

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

on that note is there a canonical "perfect" reference function we can use as a template? (that was one of my goals with #8271 btw)

Copy link
Contributor

@dom96 dom96 Jul 14, 2018

Choose a reason for hiding this comment

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

Don't have a "perfect" function to link to, but here is how these should be structured:

proc foo() =
  ## Performs the foo operation.
  ## 
  ## The foo operation is a very important operation
  ## in computer science. It solves all our problems.
  ##
  ## **Warning:** Calling ``foo`` when the ``blarg``
  ## was activated previously may cause the world to
  ## end.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've seen both these:

`foo`
vs
``foo``

and both work (and foo is simpler and more familiar for ppl familiar w markdown); ok to use single ticks ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, they aren't the same in RST.

Copy link
Member Author

Choose a reason for hiding this comment

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

indeeed, for posterity:

 `foo` vs ``foo`` vs foo

image

it's definitely not used consistently though. should that be handled by nimfix? nimpretty?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Member Author

@timotheecour timotheecour Jul 14, 2018

Choose a reason for hiding this comment

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

Don't have a "perfect" function to link to, but here is how these should be structured:

add it to contributing.md #8271 in b370902

lib/pure/os.nim Outdated
doAssert(not "".isHidden)
# TODO: decide on these:
# doAssert ".foo/".isHidden # un-specified
# doAssert ".foo/.".isHidden # un-specified
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 abuse runnableExamples for a test suite. The docs should show one or two examples, not an exhaustive list of checks.

Copy link
Member Author

Choose a reason for hiding this comment

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

done, kept the minimum sufficient set to clarify semantics

@timotheecour
Copy link
Member Author

@dom96 PTAL

timotheecour added a commit to timotheecour/Nim that referenced this pull request Jul 14, 2018
lib/pure/os.nim Outdated
## On posix: a hidden path starts with ``.`` (see examples).
##
## On OSX, in addition to the "dotfile" behaviour, existing paths with the
## "Invisible" attribute are hidden in Finder, although not in ``ls``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you discussing Finder's behaviour here? This is confusing because it implies that this function follows the Finder behaviour but I don't think that's the case.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed that comment (which was just to say there's a difference bw Finder's hidden vs ls's hidden, even though this function deals with ls's hidden)

lib/pure/os.nim Outdated
result = len(fileName) >= 2 and fileName[0] == '.' and fileName != ".."

when isMainModule:
doAssert ".foo.ext".isHidden
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

done (also moved absolutePath tests there)

lib/pure/os.nim Outdated Show resolved Hide resolved
lib/pure/os.nim Outdated Show resolved Hide resolved
lib/pure/os.nim Outdated Show resolved Hide resolved
@Varriount
Copy link
Contributor

@timotheecour This is still failing tests.

@timotheecour timotheecour mentioned this pull request Jul 30, 2018
21 tasks
Copy link
Contributor

@haltcase haltcase left a comment

Choose a reason for hiding this comment

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

Seems to just be an indentation error that's making tests fail (though now there will be some conflicts to fix up since it's been a bit). L178 of tests/stdlib/tos.nim

tests/stdlib/tos.nim Outdated Show resolved Hide resolved
@timotheecour
Copy link
Member Author

this is waiting on #9116 which I need in implementation

@timotheecour timotheecour force-pushed the pr_isHidden branch 2 times, most recently from 350c91c to 3a0ac8d Compare October 10, 2018 20:48
@timotheecour
Copy link
Member Author

timotheecour commented Oct 10, 2018

PTAL, all comments addressed
/cc @Araq I revived this now that lastPathPart was merged.

@Araq Araq merged commit 3bef851 into nim-lang:devel Oct 14, 2018
@timotheecour timotheecour deleted the pr_isHidden branch October 14, 2018 23:16
krux02 pushed a commit to krux02/Nim that referenced this pull request Oct 15, 2018
* fix nim-lang#8225 isHidden was broken on posix

* scope rest of tos.nim under blocks to avoid variable scope bugs
narimiran pushed a commit to narimiran/Nim that referenced this pull request Oct 31, 2018
* fix nim-lang#8225 isHidden was broken on posix

* scope rest of tos.nim under blocks to avoid variable scope bugs
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.

BUG: os.isHidden doesn't work with directories; should use just paths, not filesystem access
5 participants