in reply to How to represent the filesystem in DS?

Using the Graph module would save some code. The only problem you'd face is in making vertex (aka node) names which need to be unique, and you could probably solve that by making them be the full absolute path, which in filesystem semantics is unique. Then you'd use vertex and/or edge attributes for the other things, e.g. vertex "type" which could be "file", "dir", "link".

You'd need to have logic to avoid "dir" having "contain" edges to "file"/"link"/"dir" vertices that didn't have the right names. An alternative is to just have inode numerical-ID type vertex-IDs, with a "name" attribute, and have the semantics even closer to a real filesystem.

It's not so much that Graph can solve all your problems, but it would allow you to simply ignore/take for granted some of them.

  • Comment on Re: How to represent the filesystem in DS?

Replies are listed 'Best First'.
Re^2: How to represent the filesystem in DS?
by afoken (Chancellor) on Apr 04, 2022 at 16:30 UTC

    Some notes on names vs. IDs:

    Using the absolute path to identify a file is what happens e.g. with a FAT filesystem.

    Many filesystems that have a Unix history (Unix File System, MINIX file system, Extended file system family, ...) identify each file by a numeric ID. (See also inode.) Directories are just special files that associate names with file IDs.

    One quite obvious difference is that the file ID does not change when you move or rename a file.

    Another major difference of the numeric ID is that files can have zero or more names. Having no name for a file is useful for private temporary files. There is simply no way to access them except by having an open file handle. Having more than one name for a file is generally known as hardlink, and allows to refer the same file from different directories using different names. This is used e.g. by BusyBox.

    On FAT filesystems, having more than one name for the same file is generally considered a filesystem error.

    (Note that Windows Long filename support a.k.a. VFAT adds an optional alias for each part of the path. Both the short and long filenames still have to be unique. Both can be used interchangeably for each part of the path.)

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)