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

Library.create_new_library checks existence wrong #1155

Open
b4nt0 opened this issue Feb 7, 2025 · 2 comments
Open

Library.create_new_library checks existence wrong #1155

b4nt0 opened this issue Feb 7, 2025 · 2 comments

Comments

@b4nt0
Copy link

b4nt0 commented Feb 7, 2025

The create_new_library method first checks the existence of the library, and then creates the library only if it does not exist.
However, when checking existence, it uses library_name, while when creating it uses safe_name. If the library_name is not equal to the safe_name, the next time the library existence check will not succeed, however creation of the library would also fail - because the function attempts to create a different name.

The correct logic would be to convert the library name to the safe name as early as possible, and conduct further manipulations (checking existence etc.) with the safe name.

@doberst
Copy link
Contributor

doberst commented Feb 7, 2025

@b4nt0 - thanks, this is a really good catch - agree that it should be tightened. Please feel free to submit a PR if you are interested to work on it - otherwise, I will try to get to it early next week. thanks! Darren

@MacOS
Copy link
Contributor

MacOS commented Feb 9, 2025

There is also an opportunity to move some logic somewhere else, for example the following code block does not dependent on account_name, nor does it depend on library_name.

llmware/llmware/library.py

Lines 174 to 199 in 2563496

# add new file dir for this collection
self.file_copy_path = os.path.join(self.library_main_path,"uploads" + os.sep )
self.image_path = os.path.join(self.library_main_path, "images" + os.sep)
self.dataset_path = os.path.join(self.library_main_path, "datasets" + os.sep)
self.nlp_path = os.path.join(self.library_main_path, "nlp" + os.sep)
self.output_path = os.path.join(self.library_main_path, "output" + os.sep)
self.tmp_path = os.path.join(self.library_main_path, "tmp" + os.sep)
self.embedding_path = os.path.join(self.library_main_path, "embedding" + os.sep)
library_folder = os.path.exists(self.library_main_path)
# this is a new library to create -> build file paths for work products
if not library_folder:
os.mkdir(self.library_main_path)
os.mkdir(self.file_copy_path)
os.mkdir(self.image_path)
os.mkdir(self.dataset_path)
os.mkdir(self.nlp_path)
os.mkdir(self.output_path)
os.mkdir(self.tmp_path)
os.mkdir(self.embedding_path)
os.chmod(self.dataset_path, 0o777)
os.chmod(self.nlp_path, 0o777)
os.chmod(self.output_path, 0o777)
os.chmod(self.tmp_path, 0o777)
os.chmod(self.embedding_path, 0o777)

Everything it does is setting path variables, and then creating these paths and changing the access rights.

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

3 participants