Skip to content

Commit 5c7c54a

Browse files
committed
Run-From-Zip readonly file mode checks (#2230)
1 parent 19171d6 commit 5c7c54a

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/WebJobs.Script.WebHost/App_Start/WebHostResolver.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ internal void EnsureInitialized(WebHostSettings settings)
130130
_activeScriptHostConfig = CreateScriptHostConfiguration(settings);
131131
_activeHostManager = new WebScriptHostManager(_activeScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, settings);
132132
_activeReceiverManager = new WebHookReceiverManager(_activeHostManager.SecretManager);
133-
InitializeFileSystem();
133+
InitializeFileSystem(_settingsManager.FileSystemIsReadOnly);
134134

135135
if (_standbyHostManager != null)
136136
{
@@ -165,7 +165,7 @@ internal void EnsureInitialized(WebHostSettings settings)
165165
_standbyHostManager = new WebScriptHostManager(_standbyScriptHostConfig, _secretManagerFactory, _eventManager, _settingsManager, standbySettings);
166166
_standbyReceiverManager = new WebHookReceiverManager(_standbyHostManager.SecretManager);
167167

168-
InitializeFileSystem();
168+
InitializeFileSystem(_settingsManager.FileSystemIsReadOnly);
169169
StandbyManager.Initialize(_standbyScriptHostConfig);
170170

171171
// start a background timer to identify when specialization happens
@@ -285,7 +285,7 @@ private void OnSpecializationTimerTick(object state)
285285
_activeHostManager?.EnsureInitialized();
286286
}
287287

288-
private static void InitializeFileSystem()
288+
private static void InitializeFileSystem(bool readOnlyFileSystem)
289289
{
290290
if (ScriptSettingsManager.Instance.IsAzureEnvironment)
291291
{
@@ -294,17 +294,23 @@ private static void InitializeFileSystem()
294294
string home = ScriptSettingsManager.Instance.GetSetting(EnvironmentSettingNames.AzureWebsiteHomePath);
295295
if (!string.IsNullOrEmpty(home))
296296
{
297-
// Delete hostingstart.html if any. Azure creates that in all sites by default
298-
string siteRootPath = Path.Combine(home, @"site\wwwroot");
299-
string hostingStart = Path.Combine(siteRootPath, "hostingstart.html");
300-
if (File.Exists(hostingStart))
297+
if (!readOnlyFileSystem)
301298
{
302-
File.Delete(hostingStart);
299+
// Delete hostingstart.html if any. Azure creates that in all sites by default
300+
string siteRootPath = Path.Combine(home, @"site\wwwroot");
301+
string hostingStart = Path.Combine(siteRootPath, "hostingstart.html");
302+
if (File.Exists(hostingStart))
303+
{
304+
File.Delete(hostingStart);
305+
}
303306
}
304307

305-
// Create the tools folder if it doesn't exist
306308
string toolsPath = Path.Combine(home, @"site\tools");
307-
Directory.CreateDirectory(toolsPath);
309+
if (!readOnlyFileSystem)
310+
{
311+
// Create the tools folder if it doesn't exist
312+
Directory.CreateDirectory(toolsPath);
313+
}
308314

309315
var folders = new List<string>();
310316
folders.Add(Path.Combine(home, @"site\tools"));

src/WebJobs.Script/Config/ScriptSettingsManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public static ScriptSettingsManager Instance
3232

3333
public bool IsDynamicSku => WebsiteSku == ScriptConstants.DynamicSku;
3434

35+
public bool FileSystemIsReadOnly => IsZipDeployment;
36+
3537
public virtual string AzureWebsiteDefaultSubdomain
3638
{
3739
get

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ public void Initialize()
288288
// read host.json and apply to JobHostConfiguration
289289
string hostConfigFilePath = Path.Combine(ScriptConfig.RootScriptPath, ScriptConstants.HostMetadataFileName);
290290

291-
// If it doesn't exist, create an empty JSON file
292-
if (!File.Exists(hostConfigFilePath))
291+
if (!_settingsManager.FileSystemIsReadOnly && !File.Exists(hostConfigFilePath))
293292
{
293+
// If it doesn't exist, create an empty JSON file
294294
File.WriteAllText(hostConfigFilePath, "{}");
295295
}
296296

0 commit comments

Comments
 (0)