Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File destructor alters mtime/ctime #648

Open
supermihi opened this issue Aug 18, 2015 · 11 comments
Open

File destructor alters mtime/ctime #648

supermihi opened this issue Aug 18, 2015 · 11 comments

Comments

@supermihi
Copy link
Contributor

A user of pytaglib pointed out the following issue to me, which is actually inherited from taglib itself:

Changing tags of a file and then calling save() will, as expected, immediately write the changes to disk and thereby alter the file's stats. However, once the File object is destroyed, the destructor of File deletes the stream attribute of FilePrivate, which in turn closes the FileStream, which modifies the stats again. So, the mtime and ctime stats of the file won't match the time save() was called, but instead a later, potentially unpredictable (in case of garbage collection) moment.

As this is definitely not the expected behavior, I would consider it a bug. However I'm afraid that it's not easy to fix, because the File implementation heavily relies on stream being open, right?

@TsudaKageyu
Copy link
Contributor

Just a quick thought, if you can change the pytaglib's API, how about adding close() method which deletes _f to pytaglib's File class?

@supermihi
Copy link
Contributor Author

Yes, that's exactly what the user that reported the bug to be suggested. However, in upstream taglib the issue would remain - I think a close() method in Taglib::File itself would make sense too, wouldn't it?

@TsudaKageyu
Copy link
Contributor

IMO, it's logical that TagLib and pytaglib have different interfaces, since C++ and python are totally different animals. In C++, we can control the timing of destructor invocation.
Actually, it's easy to add File::close() method. But I'm not sure it will be useful. I'd like to ask some people for their opinions.

@lalinsky
Copy link
Member

I don't really understand what is causing the mtime/ctime to change.

@supermihi
Copy link
Contributor Author

@lalinsky As far as I understand, it's the del file which then closes the stream, issued explicitly in C++ and in File.__del__ in my Python API.

But I agree with @TsudaKageyu that it's okay to have File.close() in Python and not in C++, so I'll do that. Adding File::close() in C++ would probably involve a lot of changes because, at a first glance, tons of methods in File and its subclasses rely on the stream being open when called.

@sbooth
Copy link
Contributor

sbooth commented Aug 31, 2015

I assume that mtime/ctime are being modified by the call to fflush via fclose in FileStream::~FileStream() in the case where there are buffered but unwritten changes to the file handle. This got me thinking a bit and I wonder if it makes sense to add a flush() method to File that subclasses should be responsible for calling at the completion of save().

@TsudaKageyu
Copy link
Contributor

@sbooth, good catch! It's worth it to try.
However, we have to add a virtual function to IOStream or use some workaround to do it. I think it's fine to try it in taglib2.

@supermihi
Copy link
Contributor Author

I also approve flushing the stream in save(). The mtime/ctime issue however would probably remain, since fclose would still need to be called in FileStream::~FileStreaim(), I think?

@TsudaKageyu
Copy link
Contributor

Right, we need an experiment to check if it works.

@supermihi
Copy link
Contributor Author

I made this experiment, implementing IOStream::flush() and calliing it in FLAC::File::save(). Unfortunatelly, this has no effect on the mtime/ctime behavior.

@supermihi
Copy link
Contributor Author

FYI, the current pytaglib version 1.1.0 (supermihi/pytaglib@f9754bd) implements a close() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants