Skip to content

Commit

Permalink
Merge pull request #365 from Lucki/issue-#359
Browse files Browse the repository at this point in the history
Don't create symlink if there's already a blockdevice linked

Former-commit-id: 9f06f0f
  • Loading branch information
tkashkin authored Apr 15, 2020
2 parents 5a7af0d + 12b114d commit 9b41db3
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 7 deletions.
45 changes: 41 additions & 4 deletions src/data/compat/Proton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace GameHub.Data.Compat
var prefix = FSUtils.mkdir(install_dir.get_path(), @"$(FSUtils.GAMEHUB_DIR)/$(FSUtils.COMPAT_DATA_DIR)/$(id)/pfx");
var dosdevices = prefix.get_child("dosdevices");

if(FSUtils.file(install_dir.get_path(), @"$(FSUtils.GAMEHUB_DIR)/$(binary)_$(arch)").query_exists())
if(FSUtils.file(install_dir.get_path(), @"$(FSUtils.GAMEHUB_DIR)/$(id)").query_exists())
{
Utils.run({"bash", "-c", @"mv -f $(FSUtils.GAMEHUB_DIR)/$(id) $(FSUtils.GAMEHUB_DIR)/$(FSUtils.COMPAT_DATA_DIR)/$(id)"}).dir(install_dir.get_path()).run_sync();
FSUtils.rm(dosdevices.get_child("d:").get_path());
Expand All @@ -168,17 +168,54 @@ namespace GameHub.Data.Compat

var dosdevices = prefix.get_child("dosdevices");

if(dosdevices.get_child("c:").query_exists() && !dosdevices.get_child("d:").query_exists())
if(dosdevices.get_child("c:").query_exists() && dosdevices.get_path().has_prefix(runnable.install_dir.get_path()))
{
if(dosdevices.get_path().has_prefix(runnable.install_dir.get_path()))
var has_symlink = false;
for(var letter = 'd'; letter <= 'y'; letter++)
{
Utils.run({"ln", "-nsf", "../../../../../", "d:"}).dir(dosdevices.get_path()).run_sync();
if(is_symlink_and_correct(dosdevices.get_child(@"$(letter):")))
{
has_symlink = true;
break;
}
}

for(var letter = 'd'; has_symlink == false && letter <= 'y'; letter++)
{
if(!dosdevices.get_child(@"$(letter):").query_exists() && !dosdevices.get_child(@"$(letter)::").query_exists())
{
Utils.run({"ln", "-nsf", "../../../../../", @"$(letter):"}).dir(dosdevices.get_path()).run_sync();
break;
}
}
}

return prefix;
}

private bool is_symlink_and_correct(File symlink)
{
if(!symlink.query_exists())
{
return false;
}

try
{
var symlink_info = symlink.query_info("*", NONE);
if(symlink_info == null || !symlink_info.get_is_symlink() || symlink_info.get_symlink_target() != "../../../../../")
{
return false;
}
}
catch (Error e)
{
return false;
}

return true;
}

protected override string[] prepare_env(Runnable runnable, bool parse_opts=true)
{
var env = base.prepare_env(runnable, parse_opts);
Expand Down
43 changes: 40 additions & 3 deletions src/data/compat/Wine.vala
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,54 @@ namespace GameHub.Data.Compat

var dosdevices = prefix.get_child("dosdevices");

if(dosdevices.get_child("c:").query_exists() && !dosdevices.get_child("d:").query_exists())
if(dosdevices.get_child("c:").query_exists() && dosdevices.get_path().has_prefix(runnable.install_dir.get_path()))
{
if(dosdevices.get_path().has_prefix(runnable.install_dir.get_path()))
var has_symlink = false;
for(var letter = 'd'; letter <= 'y'; letter++)
{
Utils.run({"ln", "-nsf", "../../../../", "d:"}).dir(dosdevices.get_path()).run_sync();
if(is_symlink_and_correct(dosdevices.get_child(@"$(letter):")))
{
has_symlink = true;
break;
}
}

for(var letter = 'd'; has_symlink == false && letter <= 'y'; letter++)
{
if(!dosdevices.get_child(@"$(letter):").query_exists() && !dosdevices.get_child(@"$(letter)::").query_exists())
{
Utils.run({"ln", "-nsf", "../../../../", @"$(letter):"}).dir(dosdevices.get_path()).run_sync();
break;
}
}
}

return prefix;
}

private bool is_symlink_and_correct(File symlink)
{
if(!symlink.query_exists())
{
return false;
}

try
{
var symlink_info = symlink.query_info("*", NONE);
if(symlink_info == null || !symlink_info.get_is_symlink() || symlink_info.get_symlink_target() != "../../../../")
{
return false;
}
}
catch (Error e)
{
return false;
}

return true;
}

public override File get_install_root(Runnable runnable)
{
return get_wineprefix(runnable).get_child("drive_c");
Expand Down

0 comments on commit 9b41db3

Please sign in to comment.