Open Thom1729 opened 5 years ago
For the time being, I believe going through zipfile
is the proper workaround.
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.)
Currently, in order to determine whether a resource exists, you have to either:
sublime.find_resources
and check whether the desired resource is in the list. This may be inefficient if there are many resources with that name (e.g.__init__.py
). This is the approach thatsublime_lib.ResourcePath.exists()
uses.sublime.load_binary_resource()
and catchIOError
. This may be inefficient if the resource is large.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
Returns an object with the following property:
modified
: Anint
(orfloat
) that is guaranteed to increase when Sublime notices that the resource has been modified, including when its override status has changed. (This could be a timestamp, of course, as long as it's monotonic while Sublime is open.)Raises
IOError
if there is not a resource at name.Applications
ruamel.yaml
) could keep an internal cache with the name,modified
value, and the processed output, only recomputing the output whenmodified
increases.modified
before modifying and wait to continue the test untilmodified
changes.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-purposeresource_modified()
method.file_path
: The path to the current logical filesystem location of the resource, such as/Users/thom/Library/Application Support/Sublime Text 3/Installed Packages/Foo.sublime-package/bar.py
.real_path
: The path to the current physical filesystem location, such as/Users/thom/Library/Application Support/Sublime Text 3/Installed Packages/Foo.sublime-package
or (for a symlinked package)/Users/thom/Repositories/Packages/JavaScript/JavaScript.sublime-syntax
.file_paths
: A list of paths of each “version” of the resource, including overridden versions.size
: The logical size of the resource in bytes.