sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
804 stars 39 forks source link

Get metadata for resource (e.g. modification time). #2584

Open Thom1729 opened 5 years ago

Thom1729 commented 5 years ago

Currently, in order to determine whether a resource exists, you have to either:

In order to determine whether a resource has been modified, you have to read the entire resource and compare it to a previous version. It can't be done manually using the filesystem because you can't tell whether an override has disappeared.

Suggested API

sublime.stat_resource(name)

Returns an object with the following property:

Raises IOError if there is not a resource at name.

Applications

Other properties

Some other properties could be useful on the “stat” object. These could be implemented right away, eventually, or never, but the possibility of implementing them motivates having a stat_resource() method returning an object rather than a single-purpose resource_modified() method.

FichteFoll commented 5 years ago

For the time being, I believe going through zipfile is the proper workaround.

Thom1729 commented 5 years ago

It's a partial workaround, but it can't determine resource modification time. You could work around this by computing a tuple (physical file path, physical file modification time), but that could fail too in some cases (installed package file exists, override created, override destroyed). The tuple would tell you whether the resource is the same as the last time you checked, but not whether it has been changed since then. In many cases, this may be sufficient. (Possibly something to consider for sublime_lib.)