Skip to content

Commit 27e54c8

Browse files
authored
DYN-5709: publish version fix (#15408)
1 parent 884058b commit 27e54c8

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerSearchViewModel.cs

+1
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ public void Refresh()
998998
var pkgs = PackageManagerClientViewModel.ListAll();
999999

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

10031004
PopulateMyPackages(); // adding

src/DynamoCoreWpf/ViewModels/PackageManager/PackageViewModel.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public PackageViewModel(DynamoViewModel dynamoViewModel, Package model)
180180
Model = model;
181181

182182
PublishNewPackageVersionCommand = new DelegateCommand(() => ExecuteWithTou(PublishNewPackageVersion), IsOwner);
183-
PublishNewPackageCommand = new DelegateCommand(() => ExecuteWithTou(PublishNewPackage), IsOwner);
183+
PublishNewPackageCommand = new DelegateCommand(() => ExecuteWithTou(PublishNewPackage), CanSubmitNewPackage);
184184
UninstallCommand = new DelegateCommand(Uninstall, CanUninstall);
185185
UnmarkForUninstallationCommand = new DelegateCommand(UnmarkForUninstallation, CanUnmarkForUninstallation);
186186
LoadCommand = new DelegateCommand(Load, CanLoad);
@@ -410,6 +410,20 @@ private bool IsOwner()
410410
return packageManagerClient.DoesCurrentUserOwnPackage(Model, dynamoModel.AuthenticationManager.Username);
411411
}
412412

413+
/// <summary>
414+
/// You should only be able to use this if you have an installed local package and submit for the first time
415+
/// If a package with such name already exists, the process will fail during the API call, here we are not checking for that
416+
/// </summary>
417+
/// <returns></returns>
418+
private bool CanSubmitNewPackage()
419+
{
420+
if (!CanPublish) return false;
421+
// This is a round-about way to say, if we can publish a version,
422+
// then the publish has already been published,
423+
// so only allow 'Publish version'
424+
return !packageManagerClient.DoesCurrentUserOwnPackage(Model, dynamoModel.AuthenticationManager.Username);
425+
}
426+
413427
private bool CanDeprecate()
414428
{
415429
var isDeprecated = IsPackageDeprecated(Model.Name);

src/DynamoCoreWpf/ViewModels/PackageManager/PublishPackageViewModel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public PackageUploadHandle UploadHandle
184184
get { return _uploadHandle; }
185185
set
186186
{
187-
if (_uploadHandle != value)
187+
if (value != null && _uploadHandle != value)
188188
{
189189
_uploadHandle = value;
190190
_uploadHandle.PropertyChanged += UploadHandleOnPropertyChanged;

src/DynamoPackages/PackageDirectoryBuilder.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,19 @@ internal void CopyFilesIntoRetainedPackageDirectory(IEnumerable<IEnumerable<stri
328328

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

331-
if (fileSystem.FileExists(destPath))
331+
if (!Directory.Exists(Path.GetDirectoryName(destPath)))
332332
{
333-
fileSystem.DeleteFile(destPath);
333+
Directory.CreateDirectory(Path.GetDirectoryName(destPath));
334334
}
335335

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

341-
fileSystem.CopyFile(file, destPath);
342-
343344
if (file.ToLower().EndsWith(".dyf"))
344345
{
345346
dyfFiles.Add(destPath);

0 commit comments

Comments
 (0)