Skip to content

Commit

Permalink
DYN-5709: publish version fix (#15408)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnenov authored Jul 26, 2024
1 parent 884058b commit 27e54c8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ public void Refresh()
var pkgs = PackageManagerClientViewModel.ListAll();

pkgs.Sort((e1, e2) => e1.Name.ToLower().CompareTo(e2.Name.ToLower()));
pkgs = pkgs.Where(x => x.Header.versions != null && x.Header.versions.Count > 0).ToList(); // We expect compliant data structure
LastSync = pkgs;

PopulateMyPackages(); // adding
Expand Down
16 changes: 15 additions & 1 deletion src/DynamoCoreWpf/ViewModels/PackageManager/PackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public PackageViewModel(DynamoViewModel dynamoViewModel, Package model)
Model = model;

PublishNewPackageVersionCommand = new DelegateCommand(() => ExecuteWithTou(PublishNewPackageVersion), IsOwner);
PublishNewPackageCommand = new DelegateCommand(() => ExecuteWithTou(PublishNewPackage), IsOwner);
PublishNewPackageCommand = new DelegateCommand(() => ExecuteWithTou(PublishNewPackage), CanSubmitNewPackage);
UninstallCommand = new DelegateCommand(Uninstall, CanUninstall);
UnmarkForUninstallationCommand = new DelegateCommand(UnmarkForUninstallation, CanUnmarkForUninstallation);
LoadCommand = new DelegateCommand(Load, CanLoad);
Expand Down Expand Up @@ -410,6 +410,20 @@ private bool IsOwner()
return packageManagerClient.DoesCurrentUserOwnPackage(Model, dynamoModel.AuthenticationManager.Username);
}

/// <summary>
/// You should only be able to use this if you have an installed local package and submit for the first time
/// If a package with such name already exists, the process will fail during the API call, here we are not checking for that
/// </summary>
/// <returns></returns>
private bool CanSubmitNewPackage()
{
if (!CanPublish) return false;
// This is a round-about way to say, if we can publish a version,
// then the publish has already been published,
// so only allow 'Publish version'
return !packageManagerClient.DoesCurrentUserOwnPackage(Model, dynamoModel.AuthenticationManager.Username);
}

private bool CanDeprecate()
{
var isDeprecated = IsPackageDeprecated(Model.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public PackageUploadHandle UploadHandle
get { return _uploadHandle; }
set
{
if (_uploadHandle != value)
if (value != null && _uploadHandle != value)
{
_uploadHandle = value;
_uploadHandle.PropertyChanged += UploadHandleOnPropertyChanged;
Expand Down
13 changes: 7 additions & 6 deletions src/DynamoPackages/PackageDirectoryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,19 @@ internal void CopyFilesIntoRetainedPackageDirectory(IEnumerable<IEnumerable<stri

var destPath = Path.Combine(rootDir.FullName, relativePath.TrimStart('\\'));

if (fileSystem.FileExists(destPath))
if (!Directory.Exists(Path.GetDirectoryName(destPath)))
{
fileSystem.DeleteFile(destPath);
Directory.CreateDirectory(Path.GetDirectoryName(destPath));
}

if (!Directory.Exists(Path.GetDirectoryName(destPath)))
if (!fileSystem.FileExists(destPath))
{
Directory.CreateDirectory(Path.GetDirectoryName(destPath));
// Only copy new files into the destination folder.
// Under `retain folder structure`, if the destination file == source file,
// then that is simply the actual Package file we want to work with.
fileSystem.CopyFile(file, destPath);
}

fileSystem.CopyFile(file, destPath);

if (file.ToLower().EndsWith(".dyf"))
{
dyfFiles.Add(destPath);
Expand Down

0 comments on commit 27e54c8

Please sign in to comment.