Skip to content

stat module follows symlinks #3543

@sfromm

Description

@sfromm

As it is now, the stat module follow symlinks instead of returning stat information of the link itself. For example, /etc/localtime is a symlink but stat reports (abbreviated output below):

$ hacking/test-module -m library/files/stat -a 'path=/etc/localtime'


PARSED OUTPUT
{
"changed": false,
"stat": {

    "isblk": false, 
    "ischr": false, 
    "isdir": false, 
    "isfifo": false, 
    "isgid": false, 
    "islnk": false, 
    "isreg": true, 
    "issock": false, 
    "isuid": false, 

Fixing the call from os.stat to os.lstat fixes the stat module so that it properly reports that the file is a symlink (note that islnk is now true):

    "isblk": false, 
    "ischr": false, 
    "isdir": false, 
    "isfifo": false, 
    "isgid": false, 
    "islnk": true, 
    "isreg": false, 
    "issock": false, 
    "isuid": false, 

I'm happy to submit a PR to fix the stat module, but wasn't sure if the module should accept an option to follow symlinks if so desired. I think the default should be to not follow links, but am happy to implement either way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions