websockify icon indicating copy to clipboard operation
websockify copied to clipboard

In ReadOnlyTokenFile._load_targets() and TokenFileName.lookup() you keep open files

Open he1f opened this issue 9 months ago • 6 comments

ReadOnlyTokenFile

    def _load_targets(self):
  ...
      for f in cfg_files:
            for line in [l.strip() for l in open(f).readlines()]:
...

TokenFileName

    def lookup(self, token):
        token = os.path.basename(token)
        path = os.path.join(self.source, token)
        if os.path.exists(path):
            return open(path).read().strip().split(':')
        else:
            return None

It make sence to open file using context manager, to ensure it always get closed. Also I would be happy to prepare commit which migrate this code to modern pathlib, if it is interesting for you.

he1f avatar Feb 28 '25 17:02 he1f

I agree, we should definitely make sure to close opened files.

Do you want to open a PR and fix it?

CendioZeijlon avatar Mar 11 '25 16:03 CendioZeijlon

I'll be happy to open a PR, but can I use a pathlib module or I should use old-fasioned os and os.path modules?

he1f avatar Mar 11 '25 20:03 he1f

Migrating to pathlib sounds nice, go ahead!

CendioZeijlon avatar Mar 12 '25 08:03 CendioZeijlon

I've prepared local commit, but I'm not familiar how to create PR to the websockify. Can someone advise me? :)

he1f avatar Mar 13 '25 10:03 he1f

I've prepared local commit, but I'm not familiar how to create PR to the websockify. Can someone advise me? :)

Have you cloned novnc/websockify, or have you made your own fork? Easiest is if you create your own fork of websockify and commit to a new branch. Then you can simply open your fork in your browser and GitHub will suggest to open a pull request.

samhed avatar Mar 26 '25 09:03 samhed

thanks a lot, I've created a fork and after that made PR from from the fork

he1f avatar Apr 05 '25 10:04 he1f

https://github.com/novnc/websockify/pull/602 was merged and I believe we can close this issue.

kajinamit avatar Jul 15 '25 09:07 kajinamit

Thanks for investigating. Closing.

CendioOssman avatar Jul 15 '25 15:07 CendioOssman