Giter Club home page Giter Club logo

Comments (4)

johnkerl avatar johnkerl commented on June 2, 2024 1

@Poshi please let me know if #1560 (merged to main) works for you

from miller.

Poshi avatar Poshi commented on June 2, 2024 1

So far, LGTM. But would it be too much work to get the whole stats struct?

struct stat {
    dev_t     st_dev;     /* ID of device containing file */
    ino_t     st_ino;     /* inode number */
    mode_t    st_mode;    /* protection */
    nlink_t   st_nlink;   /* number of hard links */
    uid_t     st_uid;     /* user ID of owner */
    gid_t     st_gid;     /* group ID of owner */
    dev_t     st_rdev;    /* device ID (if special file) */
    off_t     st_size;    /* total size, in bytes */
    blksize_t st_blksize; /* blocksize for file system I/O */
    blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
    time_t    st_atime;   /* time of last access */
    time_t    st_mtime;   /* time of last modification */
    time_t    st_ctime;   /* time of last status change */
};

With the inode number you can see if two files are the same.
With the number of hard links you can see if there are other pointers to this file.
With the owner and group IDs you can find the files that (does not) belong tom someone.
With the different times you can distinguish different events.
Also, not sure how to test for file existence. Call stat and check if error appear, maybe?
Distinguishing files from folders, soft links, hard links and fifos will be also welcomed.
On the other hand, the block size and the number of blocks are not relevant to me, but maybe other people find it relevant.

And going one step further from the stat call, following a soft link would be an extra point :-) But that is a completely different functionality, not just querying metadata, but the actual data of a softlink, which is the immediate destination of the softlink. And it can be followed a single step, or until the end of the potential soft links chain.

from miller.

Poshi avatar Poshi commented on June 2, 2024 1

:-O I took for given that the full stat call results would be forwarded to any language that was using it.
Well, at least we have FileMode in the structure. From there, the type of file can be derived (folder, regular, link, block...).
The other missing data would be useful, but just having what you already added will go a long way :-)
It is not worth looking into non-portable things, it would be a nightmare to develop, test and maintain. Better keep to the standard and portable data.
Thanks a lot!

from miller.

johnkerl avatar johnkerl commented on June 2, 2024

@Poshi that's the C stats struct :(

Go expose this os.FileInfo and I'm using it all:

I can look into things that might vary per OS ...

from miller.

Related Issues (20)

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.