Giter Site home page Giter Site logo

jakewilliami / hiddenfiles.jl Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 0.0 566 KB

A cross-platform tool to determine if a file or directory is hidden

License: MIT License

Julia 100.00%
file file-handling filesystem freebsd fs hidden hidden-directories hidden-directory hidden-file hidden-files julia linux macos unix windows

hiddenfiles.jl's Introduction

hiddenfiles.jl's People

Contributors

jakewilliami avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

hiddenfiles.jl's Issues

Consider storing stat results in a struct

Consider storing stat results in a struct rather than indexing the st_flags attribute directly.

Something like this (untested):

struct BSDStatStruct
    st_dev::UInt64
    st_mode::UInt64
    st_nlink::UInt64
    st_uid::UInt64
    st_gid::UInt64
    st_rdev::UInt64
    st_ino::UInt64
    st_size::UInt64
    st_blksize::UInt64
    st_blocks::UInt64
    st_flags::UInt64
    st_gen::UInt64
    st_atime::Int
    st_mtim::Int
    st_ctim::Int
    st_birthtim::Int
end

function _st_flags(f::AbstractString)
    stat_t = Ref{BSDStatStruct}()
    ccall(:jl_lstat, Cvoid, (Cstring, Ref{BSDStatStruct}), f, stat_t)
    return stat_t.x.st_flags
end

Write macOS implementation of ishidden

macOS implementation is difficult, because it follows UNIX conventions whilst also having some other information.

As far as I can tell, the only other thing that determines whether a file is hidden in macOS is a certain attribute in finder flags. Once I finish this implementation, I should confirm with Stefan, as he may know about some other file attributes that we need to check (in his comment he mentions there are three, on top of the UNIX standard).

Related:

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

Write tests/implement CI/CD

Write tests for these functions! I think I will have to create files and make them hidden or not hidden, which might mean that I have to create whole functions to change file attributes. I should also test on directories and files.

Refactor helper methods into subdirectory

Currently the main module is very messy. I would like to keep only the business logic in this file, and any helper methods tucked away in some subdirectory.

Prospective directory structure:

src
├── utils
│  └── darwin.jl
└── HiddenFiles.jl

Ensure directory references (. and ..) are hidden

I thought . and .. are symbolic links or something like that, but they actually exist in the file system, so I shouldn’t follow them/expand them! Therefore, anything whose base name is . or .. are actually hidden.

Enchancement: use CFStringGetCharacters over iteration and CFStringGetCharacterAtIndex

Currently we use CFStringGetCharacterAtIndex and iterate over the CF String to construct the String. This is obviously inefficient, and we should use CFStringGetCharacters instead.

Some example code which I haven't quite got working yet:

mutable struct CFRange
    length::Int
    location::Int
end
function _cfstring_get_characters(cfstr::Cstring, range::CFRange)
    charbuf = Vector{UInt8}(undef, range.length)
    ccall(:CFStringGetCharacters, Ptr{UInt32}, (Cstring, Ptr{Cvoid}, Ptr{Cvoid}), cfstr, pointer_from_objref(range), charbuf)
    return charbuf
end
function _string_from_cfstring(cfstr::Cstring, encoding::Unsigned = K_CFSTRING_ENCODING_MACROMAN)
    strlen = _cfstring_get_length(cfstr)
    maxsz = _cfstring_get_maximum_size_for_encoding(strlen, encoding)
    return _cfstring_get_characters(cfstr, CFRange(maxsz, 0))
end

Then, we will simple be able to write

function _string_from_cf_string(cfstr::Cstring)
    charbuf = _string_from_cfstring(cfstr)
    return String(charbuf)
end

Consider using ObjectiveC.jl

Currently I have implemented CF* structures and functions within Julia. It would be ideal if I could call Objective-C directly (using ObjectiveC.jl), however currently it appears this project has been abandoned.

Ensure string encoding for CFStrings work with non-UTF-8 pathnames

Unfortunately on macOS, to check for whether a path is a package or bundle, the MDItem* functions necessitate the use of CFStrings, and all of the joys that come with them. As I have had to implement these myself, they are probably not very robust.

In the interest of everyone who doesn't use the Latin alphabet, I should ensure the string interface with Apple's Core Foundation works robustly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.