Skip to content

Commit

Permalink
Merge pull request #12 from Azure-App-Service/jennylaw-fixfunctions
Browse files Browse the repository at this point in the history
Fixup post-receive for kudulite migration when SCM_REPOSITORY_PATH is…
  • Loading branch information
JennyLawrance authored Feb 8, 2019
2 parents d2cbffb + 8589851 commit dd4d1f0
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions Kudu.Services.Web/KuduWebUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,17 @@ internal static string GetRequestTraceFile(IServiceProvider serviceProvider)
/// <param name="environment"></param>
internal static void MigrateToNetCorePatch(IEnvironment environment)
{
var gitPostReceiveHookFile = Path.Combine(environment.RepositoryPath, ".git", "hooks", "post-receive");
// Get the repository path:
// Use value in the settings.xml file if it is present.
string repositoryPath = environment.RepositoryPath;
IDeploymentSettingsManager settings = GetDeploymentSettingsManager(environment);
if (settings != null)
{
var settingsRepoPath = DeploymentSettingsExtension.GetRepositoryPath(settings);
repositoryPath = Path.Combine(environment.SiteRootPath, settingsRepoPath);
}

var gitPostReceiveHookFile = Path.Combine(repositoryPath, ".git", "hooks", "post-receive");
if (FileSystemHelpers.FileExists(gitPostReceiveHookFile))
{
var fileText = "";
Expand All @@ -204,7 +214,6 @@ internal static void MigrateToNetCorePatch(IEnvironment environment)
}
}


internal static void TraceShutdown(IEnvironment environment, IDeploymentSettingsManager settings)
{
ITracer tracer = GetTracerWithoutContext(environment, settings);
Expand Down Expand Up @@ -339,6 +348,46 @@ internal static void EnsureValidDeploymentXmlSettings(IEnvironment environment)
}
}

/// <summary>
/// Get Deploployment settings
/// </summary>
/// <param name="environment"></param>
private static IDeploymentSettingsManager GetDeploymentSettingsManager(IEnvironment environment)
{
var path = GetSettingsPath(environment);
if (!FileSystemHelpers.FileExists(path))
{
return null;
}

IDeploymentSettingsManager result = null;

try
{
var settings = new DeploymentSettingsManager(new XmlSettings.Settings(path));
settings.GetValue(SettingsKeys.TraceLevel);

result = settings;
}
catch (Exception ex)
{
DateTime lastWriteTimeUtc = DateTime.MinValue;
OperationManager.SafeExecute(() => lastWriteTimeUtc = File.GetLastWriteTimeUtc(path));
// trace initialization error
KuduEventSource.Log.KuduException(
ServerConfiguration.GetApplicationName(),
"Startup.cs",
string.Empty,
string.Empty,
string.Format("Invalid '{0}' is detected and deleted. Last updated time was {1}.", path,
lastWriteTimeUtc),
ex.ToString());
File.Delete(path);
}

return result;
}

internal static void PrependFoldersToPath(IEnvironment environment)
{
var folders = PathUtilityFactory.Instance.GetPathFolders(environment);
Expand Down Expand Up @@ -451,4 +500,4 @@ internal static string GetSettingsPath(IEnvironment environment)
return Path.Combine(environment.DeploymentsPath, Constants.DeploySettingsPath);
}
}
}
}

0 comments on commit dd4d1f0

Please sign in to comment.