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

Created on 6 Jul 2018  路  10Comments  路  Source: nim-lang/Nim

  • [x] currently "/Users/timothee/.ssh".isHidden is false
    it should be true (ie, isHidden shouldn't care on whether the argument is a file or a directory)
    Current behavior is very unintuitive and causes bugs: eg the fix for https://github.com/citycide/glob/issues/7#issuecomment-403144140 doesn't work

(haven't tried on windows but maybe it's similar).

  • [x] currently, "foo/.unexistingpath".isHidden returns false (assuming that path doesn't exist in filesystem). It should return true IMO. on posix, isHidden shouldn't access the filesystem, but just use string manipulation. On windows, maybe that's not the case.

/cc @Araq if you agree with these I can send a PR to fix posix

EDIT

  • java: behaves same as I recommend:
// package com.javatutorialhq.java.examples;
import java.io.File;
public class test1 {
  public static void main(String[] args) {
    File file = new File(".foo");
    boolean result = file.isHidden();
    System.out.println(file + " isHidden: " + result);
  }
}
//prints: .foo isHidden: true
bool isHidden(const bf::path &p)
{
    bf::path::string_type name = p.filename();
    if(name != ".." &&
       name != "."  &&
       name[0] == '.')
    {
       return true;
    }

    return false;
}

isHidden("a/.foo") => true

Stdlib

Most helpful comment

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

All 10 comments

Heh, I don't know. Probably you're right and it should care about paths in general.

As is often the case, it's good to ask this question: how do other languages handle this?

@dom96 I edited my answer above to add what I could find from other languages (couldn't find much lang that support isHidden); everything I found is 100% consistent with my proposal.

Regarding whether it should apply to both files and dirs, that's just common sense.
Regarding whether it should work (on posix) on paths that don't exist, that's also common sense since only string is accessed to determine that, and that's what all answers I could find did anyway (on posix)

@dom96 It's surprising that this isn't in more stdlibs considering it's a bit of a pain to handle across systems. Yes it's fairly easy on posix but Windows requires attribute checks. I really appreciate that this is included.

Should dots be taken into account even on Windows though? Maybe optionally? Lots of dot files are not technically hidden when they probably should be.

@citycide @dom96 @Araq
how about the following:
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)

Should dots be taken into account even on Windows though? Maybe optionally? Lots of dot files are not technically hidden when they probably should be.

Never ever. Our stdlib is not responsible for fixing half-assed Unix ports to Windows.

os.isDotPath would not be enough: I am pretty sure that on Linux files that end in ~ are hidden as well.

If the OS exposes a way to figure out whether a file or directory is hidden, that should be used (what happens on windows anyway). I am not sure whether something like that exists on Linux, though

@andreaferretti

os.isDotPath would not be enough: I am pretty sure that on Linux files that end in ~ are hidden as well.

just tried, doesn't seem like that's correct:

total 0
-rw-r--r-- 1 timothee 0 Jul 11 02:06 foo~
-rw-r--r-- 1 timothee 0 Jul 11 02:06 foo~2
prompt:lhmbp /private/tmp/d01  0.020 $ ls -a
total 0
drwxr-xr-x  5 timothee 160 Jul 11 02:06 ./
drwxrwxrwt 28 root     896 Jul 11 02:06 ../
-rw-r--r--  1 timothee   0 Jul 11 02:06 .bar
-rw-r--r--  1 timothee   0 Jul 11 02:06 foo~
-rw-r--r--  1 timothee   0 Jul 11 02:06 foo~2

likewise on OSX.

It seems you're right. Most file managers hide those as well, though

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dom96 picture dom96  路  47Comments

Araq picture Araq  路  74Comments

zielmicha picture zielmicha  路  37Comments

xland picture xland  路  26Comments

yglukhov picture yglukhov  路  46Comments