4TUResearchData / djehuty

The 4TU.ResearchData repository system
https://data.4tu.nl
Other
27 stars 10 forks source link

Use 'pathlib' to handle paths #23

Closed manuGil closed 1 month ago

manuGil commented 1 month ago

We noticed that is some parts of wsgi.py, paths are treated as strings. This may cause problems when some of the paths contain tailing '/' or not. for example, in ___git_create_repository(), the path git_directory is form by combining two strings separated by a /

https://github.com/4TUResearchData/djehuty/blob/fffe895fa8bdf58e01ba865ae9f0fcfc6c6ab182/src/djehuty/web/wsgi.py#L8016-L8020

A better approach would be something like this:

    def __git_create_repository (self, git_uuid):
        git_repo_name = f"{git_uuid}.git" # assuming git_uuid is not a path
        git_directory = os.path.join(self.db.storage, git_repo_name)
        if not os.path.exists (git_directory):
            initial_repository = pygit2.init_repository (git_directory, True)
            if initial_repository:
roelj commented 1 month ago

Thank you @manuGil . Would you like to create/prepare a patch? :-)

manuGil commented 1 month ago

Thank you @manuGil . Would you like to create/prepare a patch? :-)

I can make a patch for this particular function. But this probably needs to be check elsewhere as well to be consistent in the way paths are handled.

roelj commented 1 month ago

I can make a patch for this particular function.

That would be great!

roelj commented 1 month ago

Thank you @manuGil! The patch has been applied in b831668fff411db5ace4d8b83bd2e792210b0293. Over the next month I'll try to convert the other cases as well.