Note that there are some explanatory texts on larger screens.

plurals
  1. POmake file appear readonly to a library function
    primarykey
    data
    text
    <p>I'm using a library that can read or write some metadata that I need from files.</p> <p>I only need to read and I know that my files are on slow storage.</p> <p>I noticed that while reading the values I need is very fast, closing the files is slow. Basically, if I <code>open(); read(); close()</code> each file my program is quite slow, but if I only <code>open(); read()</code> during operation and <code>close()</code> right before exit (i.e. I let my run-time close the files during finalization of the leaked objects) the program runs fast, but stops for several seconds just before exit - when the files are being closed. </p> <p>On the other hand, if I remove write permission from the files this doesn't happen: it seems that files open readonly are closed much faster than the files open read-write. It could be that the library writes metadata on close "just to be sure" if the file is writable, or some other reason, but anyway - it's impossible to specify for the library that I wan't to open the file only for reading: it tries to be intelligent and decides based on file permissions.</p> <p>At the moment to speed things up I'm changing file permissions just before opening it and restoring permissions after the metadata is read. It works, but it feels wrong. </p> <p>Is there a way in linux / unix to make files appear readonly to the current process temporarily? I can't use setuid(2) because the program is ran by unpriviledged user (or am I wrong about this?).</p> <p><strong>details</strong></p> <p>The library is <a href="https://github.com/robinst/taglib-ruby" rel="nofollow">taglib-ruby</a> which is in turn a wrapper around <a href="http://taglib.github.io/" rel="nofollow">taglib</a>'s C++ API.</p> <p>The program may list the tracks on the device and needs to know their length in seconds (the reason I use taglib), but the same media will be written to (new tracks uploaded, some tracks deleted) hence I can't just force users to mount the device readonly.</p> <p>I realize that a better solution would be patching taglib to allow to specify that I just want to read the metadata, then patch taglib-ruby to wrap the new API. But I'm not up to it, plus I have a workaround already, thus not much insetive to go down that route. I'm just wondering if there is a better workaround.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload