P
P
Pavel2018-01-09 17:16:00
linux
Pavel, 2018-01-09 17:16:00

Why can't I display information about a symbolic link on Linux?

core class
Node = namedtuple('Node', ['name', 'type', 'size', 'datemodified', 'weight'])


class Core:
    def __init__(self):
        self.rootPath = '/fileuploader/rootdir'
        self.currientPath = self.rootPath
    def ScanDir(self):
        files = []
        with os.scandir(self.currientPath) as it:
            for entry in it:
                if entry.is_dir():
                    files.append(Node(
                        entry.name,
                        'folder',
                        0,
                        datetime.fromtimestamp(entry.stat().st_mtime),
                        0)
                    )
                else:
                    files.append(Node(
                        entry.name,
                        str(mimetypes.guess_type(entry.path)[0]),
                        entry.stat().st_size,
                        datetime.fromtimestamp(entry.stat().st_mtime),
                        len(str(mimetypes.guess_type(entry.path)[0]))
                    ))
        files.sort(key=attrgetter('weight'))
        return files

There is a core class, and a ScanDir method that scans a directory and adds information about the contained files to the "Node" structure. These structures are then used in the flask template. The path /fileuploader/rootdir contains 5 directories, or rather 3 directories and 2 symbolic links to directories.
Listing the contents of a folder:
>>> print([entry for entry in os.scandir('/fileuploader/rootdir')])
[<DirEntry 'Soft'>, <DirEntry 'Games'>, <DirEntry 'Video'>, <DirEntry 'Books'>, <DirEntry 'Music'>]

But the ScanDir function crashes at the moment
datetime.fromtimestamp(entry.stat().st_mtime)
with the error FileNotFoundError: [Errno 2] No such file or directory: '/fileuploader/rootdir/Books' .
I did debugging on Windows (Development is carried out in a docker container, i.e. the project itself is, as it were, on Linux, but the file folder is mounted from Windows), I made a symbolic link via mklink / j , everything works great. It crashes on Linux. Links on Linux are working, I checked through mc, plus several services are tied to these links that also work.
What could be the problem?
Trying to display information about files in the interactive console of the flask

>>> [print(entry.stat()) for entry in os.scandir('/fileuploader/rootdir')]
os.stat_result(st_mode=16877, st_ino=14942408, st_dev=2052, st_nlink=2, st_uid=1000, st_gid=100, st_size=4096, st_atime=1515497744, st_mtime=1512115670, st_ctime=1512115670)
os.stat_result(st_mode=16877, st_ino=15598763, st_dev=2052, st_nlink=5, st_uid=487, st_gid=486, st_size=4096, st_atime=1515497739, st_mtime=1511698768, st_ctime=1511698768)
os.stat_result(st_mode=16893, st_ino=14942343, st_dev=2052, st_nlink=6, st_uid=1000, st_gid=100, st_size=4096, st_atime=1515497745, st_mtime=1514188702, st_ctime=1514188702)
Traceback (most recent call last):

    File "<debugger>", line 1, in <module>

    [print(entry.stat()) for entry in os.scandir('/fileuploader/rootdir')]

    File "<debugger>", line 1, in <listcomp>

    [print(entry.stat()) for entry in os.scandir('/fileuploader/rootdir')]

    FileNotFoundError: [Errno 2] No such file or directory: '/fileuploader/rootdir/Books'


Full error output

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2018-01-09
@rusbaron

The fact is that I mount the home directory to the container, /home/user/Downloads, it contains 3 directories and 2 symbolic links to the /opt/Downloads directory. Everything works fine in bash of Linux itself, I calmly go through a symbolic link, but in the container there is an error
. the home folder was mounted, external links were not available, so the external folder had to be mounted to the container along the same path.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question