[SOLVED] One file of every type that is guaranteed to be in every distro?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
One file of every type that is guaranteed to be in every distro?
Hello everyone! I was wondering if anyone could give me one filetype of EVERY type that is guaranteed to exist in EVERY Linux distro. I would like the path to be an absolute path if possible.
For regular files, I have used:
Code:
/lib/libc.so
For directory files, I have used:
Code:
/tmp
For system links, I have used:
Code:
/dev/fd
Now I want one Block, Character, Pipe and Socket file, and I'm good to go! Any ideas? Also, if you are not 100% sure that it is present in every single distro, but it's present in the most popular ones from what you know, it will be ok for now! I can do more research later! And well, someone may find and report it!
Thanks in advance!
EDIT:
Thank you everyone for your help! The final solution has been provided by @boughtonp in message #18! I wish you all to have an amazing day!
Last edited by rempas; 09-23-2023 at 08:04 AM.
Reason: Solution message
As per the first example at that link: If file extensions were always three letters, it doesn't matter. When they're not, it matters.
Extensions does not matter. Extensions can be whatever (at least on Unix). When I talk about filetypes I mean about REAL filetypes. E.g. Regular files, Directory types, Block files, Links etc.
Of course, not anybody knows that, and I'm aware of that. I know the support would be limited, but it's still better than nothing, and I'm very grateful to anyone who wants to help!
Quote:
Originally Posted by boughtonp
Tests should use controlled resources: i.e. ones you have explicitly created yourself for the purposes of the tests.
That's the best way to guarantee they will exist, even if someone arbitrarily decides to move/change a whole tree.
Thank you for the advice! Unfortunately, I cannot do that in that case as, I first need to make sure that the functions (if you don't know what's that, let's say a block of code that does a specific job) that check if a file exists and what type is it first work in order to create a file and then been able to make sure that the latter functions work. In other words, the latter functions depend on the first ones.
Surely you can come up with a /dev/ node for each of these yourself?
Give up on pipes and sockets; they're created as needed.
I don't think that I'm getting through. I cannot "give up" on them or "come up" (I suppose you mean create them myself? If not, I'm sorry, but I don't understand) for them myself.
For my task, I want these files to be present in every (or at least, the most popular ones) disto by default. Sorry if I wasn't very clear in the original post.
Again, based on the limited explanation that you've given so far: you've got the wrong approach/mindset.
The point of unit tests is to be self-contained - that means stubbing/mocking external interfaces, so that a success or failure is dependent solely on the unit of functionality being tested.
If code needs to react differently when a path points to a directory or a regular file or a special file, don't rely on external paths, have a simple setup script that creates them.
If you try to depend on arbitrary locations external to your code, the code becomes brittle and will break when one of those locations either doesn't exist, or currently exists but later gets moved, or exists as a different type, or has unexpected permissions.
Block devices are typically some type of storage medium i.e. PATA, USB, SATA and SCSI drives are /dev/sdx but you also have NVMe technology so this is more hardware dependent then software. Blindly writing to a block device could corrupt the filesystem(s). To write to a filesystem or check if a file exists does not need block level access.
Standard on any linux distribution are character devices like /dev/null, /dev/random, /dev/zero or /dev/ttyX. You usually read from /dev/random but you can write as well.
pipes and sockets depend on the distribution, how it was configured at installation and what services are currently running. You can find pipes and sockets via the find command i.e.
find / -type s,p
If you try to write to an existing socket or pipe I would expect you would need to know the service communication protocol otherwise nothing is going to happen, you might not get a response or you might "crash" the service.
Again, based on the limited explanation that you've given so far: you've got the wrong approach/mindset.
The point of unit tests is to be self-contained - that means stubbing/mocking external interfaces, so that a success or failure is dependent solely on the unit of functionality being tested.
If code needs to react differently when a path points to a directory or a regular file or a special file, don't rely on external paths, have a simple setup script that creates them.
If you try to depend on arbitrary locations external to your code, the code becomes brittle and will break when one of those locations either doesn't exist, or currently exists but later gets moved, or exists as a different type, or has unexpected permissions.
I do understand your point and it is true. However, in my case, I NEED to depend on external files and there is no other way. I mean, as my functions will just be "system call", one could say that I don't even have to test them and that they'll always work and be stable (they'll never change in the future) but I don't want to go with that logic and I want to test them anyway. I first need to be able to check the type of file successfully, and then make sure that I can create the files with the given types that I want. So like I said, I cannot create the files first and then test their file type because I first need to make sure that the functions that check the file types work. For every other type of application, I wouldn't have to require to anything external but for this library, I have too...
The reason I asked for files that exists in every distro is, exactly, so my tests don't fail because these files doesn't exist in some distros. As for the case they are moved in the future, the test suit will be updated as needed! However, things like "lib/libc.so" and "/dev/fd" will probably never move, so I'm fine. But again, if they do, I can always update the test suit.
If you are a programmer (which, based on your knowledge about test-suits, I suppose you are), I can give you detailed information about what I'm trying to do (even give you a link to my repo if you are so much curious) if you are curious to know.
Block devices are typically some type of storage medium i.e. PATA, USB, SATA and SCSI drives are /dev/sdx but you also have NVMe technology so this is more hardware dependent then software. Blindly writing to a block device could corrupt the filesystem(s). To write to a filesystem or check if a file exists does not need block level access.
Standard on any linux distribution are character devices like /dev/null, /dev/random, /dev/zero or /dev/ttyX. You usually read from /dev/random but you can write as well.
pipes and sockets depend on the distribution, how it was configured at installation and what services are currently running. You can find pipes and sockets via the find command i.e.
find / -type s,p
If you try to write to an existing socket or pipe I would expect you would need to know the service communication protocol otherwise nothing is going to happen, you might not get a response or you might "crash" the service.
As posted your going about it the wrong way.
Thank you for the information, that will come in handy! I don't want to either read or write to any of these files. I just want to use them to guarantee that my functions work.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.