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

Fix DeployAppCommand to work right with source-directory parameter #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion src/AppHarbor/Commands/DeployAppCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ public DeployAppCommand(IApplicationConfiguration applicationConfiguration, IAcc
_writer = writer;

_sourceDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
OptionSet.Add("source-directory=", "Set source directory", x => _sourceDirectory = new DirectoryInfo(x));
OptionSet.Add("source-directory=", "Set source directory", x =>
{
_sourceDirectory = new DirectoryInfo(x);

if (!_sourceDirectory.Exists)
{
throw new CommandException(string.Format("The directory '{0}' does not exist or is not accessible", _sourceDirectory.FullName));
}
});

_excludedDirectories = new List<string> { ".git", ".hg" };
OptionSet.Add("e|excluded-directory=", "Add excluded directory name", x => _excludedDirectories.Add(x));
Expand Down
20 changes: 20 additions & 0 deletions src/AppHarbor/CompressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@
using System.IO;
using System.Linq;
using ICSharpCode.SharpZipLib.Tar;
using System;

namespace AppHarbor
{
public static class CompressionExtensions
{
public static void ToTar(this DirectoryInfo sourceDirectory, Stream output, string[] excludedDirectoryNames)
{
string previousCurrDir = Environment.CurrentDirectory;
try
{
// Chgange the current directory to the source directory
// because the Tar library use it as a reference point
// and it will leave the specified source-directory in each
// tar file path otherwise.
Environment.CurrentDirectory = sourceDirectory.FullName;

TarDirectory(sourceDirectory, output, excludedDirectoryNames);
}
finally
{
Environment.CurrentDirectory = previousCurrDir;
}
}

private static void TarDirectory(DirectoryInfo sourceDirectory, Stream output, string[] excludedDirectoryNames)
{
var archive = TarArchive.CreateOutputTarArchive(output);

Expand Down