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

Avoid trying to add deleted files in zip when downloading changes #11992

Merged
merged 6 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions backend/src/Designer/Controllers/RepositoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Configuration;
using Altinn.Studio.Designer.Enums;
using Altinn.Studio.Designer.Helpers;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.RepositoryClient.Model;
Expand Down Expand Up @@ -558,8 +559,11 @@
return BadRequest("User does not have a local clone of the repository.");
}

var outStream = new MemoryStream();
using (var archive = new ZipArchive(outStream, ZipArchiveMode.Create, leaveOpen: true))
var zipType = full ? "full" : "changes";
var zipFileName = $"{org}-{repository}-{zipType}.zip";
var zipFilePath = Path.Combine(Path.GetTempPath(), zipFileName);
standeren marked this conversation as resolved.
Show resolved Hide resolved

using (var archive = new ZipArchive(new FileStream(zipFilePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read, 512, FileOptions.DeleteOnClose), ZipArchiveMode.Create, leaveOpen: false))
{
IEnumerable<string> changedFiles;
if (full)
Expand All @@ -568,18 +572,19 @@
}
else
{
changedFiles = _sourceControl.Status(org, repository).Select(f => f.FilePath);
}
changedFiles = _sourceControl
.Status(org, repository)
.Where(f => f.FileStatus != FileStatus.DeletedFromWorkdir)
.Select(f => f.FilePath);
};

foreach (var changedFile in changedFiles)
{
archive.CreateEntryFromFile(Path.Join(appRoot, changedFile), changedFile);
}
}

outStream.Seek(0, SeekOrigin.Begin);

return File(outStream, "application/zip", $"{org}-{repository}.zip");
return File(System.IO.File.ReadAllBytes(zipFilePath), "application/zip", zipFileName);
Fixed Show fixed Hide fixed
}

private List<string> GetFilesInDirectory(string appRoot, DirectoryInfo currentDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public List<RepositoryContent> Status(string org, string repository)
{
RepositoryContent content = new();
content.FilePath = item.FilePath;
content.FileStatus = (Altinn.Studio.Designer.Enums.FileStatus)item.State;
repoContent.Add(content);
}
}
Expand Down Expand Up @@ -482,8 +483,8 @@ private void CommitAndPushToBranch(string org, string repository, string branchN

if (!remote.PushUrl.Equals(remoteUrl))
{
// This is relevant when we switch beteen running designer in local or in docker. The remote URL changes.
// Requires adminstrator access to update files.
// This is relevant when we switch between running designer in local or in docker. The remote URL changes.
// Requires administrator access to update files.
repo.Network.Remotes.Update("origin", r => r.Url = remoteUrl);
}

Expand Down
Loading