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

Implement ishidden on ZFS for BSD #12

Open
jakewilliami opened this issue Sep 7, 2022 · 5 comments
Open

Implement ishidden on ZFS for BSD #12

jakewilliami opened this issue Sep 7, 2022 · 5 comments

Comments

@jakewilliami
Copy link
Owner

jakewilliami commented Sep 7, 2022

See also: #3, #13.

@jakewilliami
Copy link
Owner Author

I should consider implementing on OpenBSD and NetBSD, not just FreeBSD. However, Julia itself only officially supports FreeBSD, so we will see.

jakewilliami added a commit that referenced this issue Sep 11, 2022
BSD-related OS's (i.e., FreeBSD and macOS) can have the st_flags check
applied to them (as I implemented this for macOS), so this function
was moved out into a separate branch.

ZFS function stubs were also created (with errors in case people try
to use them at this stage in development) so that I can (hopefully
soon) start implementing them.

Addresses #1, #3, #12, #13
jakewilliami added a commit that referenced this issue Sep 11, 2022
Apparently you can get ZFS on macOS:
https://github.com/openzfsonosx/zfs

Addresses #1, #12, #13
@jakewilliami
Copy link
Owner Author

Interestingly, using the _st_flags check, running _isinvisible on FreeBSD on /mnt/Media/.zfs/ returns false, but mounting it onto my macOS, calling _isinvisible on /Volumes/Media/.zfs/ returns true. Perhaps it's my construction of the stat struct. Will investigate.

@jakewilliami
Copy link
Owner Author

Some more testing: we run the following on FreeBSD:

#include  <stdio.h>
#include <sys/stat.h>

int main() {
    char *fd = "/mnt/.zfs";
    struct stat statbuf;
    stat(fd, &statbuf);
    unsigned int isinvisible = statbuf.st_flags & ((unsigned int) 32768);  /* 0x00008000 */
    printf("%u\n", isinvisible);
    return 0;
}

And this returns:

$ cc test.c && ./a.out
0

So perhaps the uv stat struct is fine, but the behaviour itself on FreeBSD is different to when it's on macOS. That would make sense.

@jakewilliami
Copy link
Owner Author

After some further testing, I believe the jl_lstat call is working as expected:

Path st_flags (C) st_flags (Julia)
/mnt/.zfs 0x000 0x000
/mnt 0x800 0x800
/root/projects 0x800 0x800
/root/.bashrc 0x800 0x800
/usr/lib 0x800 0x800
/usr/local/bin/bash 0x800 0x800
/dev 0x000 0x000

Hence, it does seem that out uv stat call is working well. However, this does expose a greater question: is does st_flags ever actually expose hidden files on FreeBSD? The answer appears to be no: I ran the following script and had nothing print:

using HiddenFiles

function HiddenFiles._isinvisible(fs::Vector{String}; show_true::Bool = true)
    for f in fs
        i = HiddenFiles._isinvisible(f)
        show_true && i && println(f)
    end
end

function main(root_path::AbstractString)
    for (root, dirs, files) in walkdir(root_path, follow_symlinks=true, onerror=println)
        try
            _isinvisible(joinpath.(root, files))
        catch
            continue
        end
    end
end

main("/")

However, the st_flags attribute does appear to be set, at least, so that must imply that it's possible that we can derive an answer from st_flags on FreeBSD.

Further testing should check if this flag is being set on Linux. Perhaps this check should be a global UNIX thing?

This comment pertains to #3.

@jakewilliami
Copy link
Owner Author

Considering how long it has taken me to get literally nowhere regarding this implementation, I think I would like to save this feature for a different version, in the interest of getting a useable package registered.

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

No branches or pull requests

1 participant