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

Shared folder strategies #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

demoran23
Copy link

Tangentially related to issue #33, this adds the concept of a shared folder strategy. For SD.Next, it will update the config.json file with the appropriate paths and use them. With that configuration, there should be no need to juggle symlinks in the filesystem.

A similar strategy can be applied to Comfy (cf #33), but it hasn't been implemented here.

@github-actions
Copy link

github-actions bot commented Jul 19, 2023

CLA Assistant Lite bot CLA Assistant bot All Contributors have signed the CLA.

@demoran23
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Copy link
Contributor

@mohnjiles mohnjiles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR! I definitely like the idea behind this, avoiding symlinks while still achieving the shared models directory would be sweet. Just have a couple suggestions & ideas to ponder.

Comment on lines +22 to +27
public async Task ExecuteAsync(BasePackage package)
{
var installedPackage = settingsManager
.Settings
.InstalledPackages
.Single(p => p.PackageName == package.Name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things here -

  1. In the InstallerViewModel, this is called before the InstalledPackage object has been added to the settings, so this will throw an exception unless they had a previous install of the same package (in which case it'd be using the wrong paths anyway).

  2. It is possible to have two different installs of the same package, so using .Single() with the PackageName here could possibly throw. If possible, its best to use the Guid Id when trying to find an InstalledPackage.

  3. Since the name property is all that's used from the BasePackage, could the method parameter here just be the name of the package instead of the full thing?

Comment on lines +31 to +32
var json = await File.ReadAllTextAsync(configFilePath);
var job = JsonConvert.DeserializeObject<JObject>(json)!;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been using System.Text.Json for our json parsing, as it has improved quite a bit since the initial release. So that we don't have two different json parsing libraries involved, would it be possible to redo this using System.Text.Json? I believe it should have a similar class to JObject called JsonObject

Comment on lines +160 to +163
if (basePackage.SharedFolderStrategy is LinkedFolderSharedFolderStrategy)
sharedFolders.UpdateLinksForPackage(basePackage, packagePath);
else
await basePackage.SharedFolderStrategy.ExecuteAsync(basePackage);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could you please put curly braces around these statements? According to our style guidelines:

Only omit curly braces from if statements if the statement immediately following is a return.

Thank you!

/// <summary>
/// The shared folders that this package supports.
/// Mapping of <see cref="SharedFolderType"/> to the relative path from the package root.
/// </summary>
public virtual Dictionary<SharedFolderType, string>? SharedFolders { get; }


public abstract ISharedFolderStrategy SharedFolderStrategy { get; protected set; }
Copy link
Contributor

@mohnjiles mohnjiles Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it may be better to implement an abstract method, along the lines of ExecuteSharedFolderStrategy instead - we could inject the ISharedFolders to the implementations of this, so that the packages without custom strategies can just call the original SharedFolders method without the is LinkedFolderSharedFolderStrategy check.

You could still inject the strategies to the classes that need them, we just wouldn't expose the whole strategy object to the callers. You might also need to pass in the directory as a parameter, since the BasePackage doesn't know where it's installed (most of the time).

It might also eliminate the need for LinkedFolderSharedFolderStrategy and avoid the circular reference shenanigans.

I hope that made sense 😅

@gravyboatcaptain
Copy link

I'm quite eager to see this implemented. I hope @demoran23 is able to make these changes.

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

Successfully merging this pull request may close these issues.

None yet

3 participants