From 1d31c1687c0ab3ec50f5769d7386b53a569d11ce Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 10 Oct 2011 18:11:22 -0700 Subject: [PATCH 1/2] Fixed issue with invalid AirTimes for series causing Upcoming Views to fail. --- .../Controllers/UpcomingController.cs | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/NzbDrone.Web/Controllers/UpcomingController.cs b/NzbDrone.Web/Controllers/UpcomingController.cs index cbcad6395..9f887bf2a 100644 --- a/NzbDrone.Web/Controllers/UpcomingController.cs +++ b/NzbDrone.Web/Controllers/UpcomingController.cs @@ -38,9 +38,9 @@ public ActionResult _AjaxBindingYesterday() EpisodeNumber = u.EpisodeNumber, Title = u.Title, Overview = u.Overview, - AirDateTime = u.AirDate.Value.Add(Convert.ToDateTime(u.Series.AirTimes).TimeOfDay), + AirDateTime = GetDateTime(u.AirDate.Value, u.Series.AirTimes), AirDate = u.AirDate.Value.ToBestDateString(), - AirTime = Convert.ToDateTime(u.Series.AirTimes).ToShortTimeString(), + AirTime = String.IsNullOrEmpty(u.Series.AirTimes) ? "?" : Convert.ToDateTime(u.Series.AirTimes).ToShortTimeString(), Status = u.Status.ToString() }); @@ -59,9 +59,9 @@ public ActionResult _AjaxBindingToday() EpisodeNumber = u.EpisodeNumber, Title = u.Title, Overview = u.Overview, - AirDateTime = u.AirDate.Value.Add(Convert.ToDateTime(u.Series.AirTimes).TimeOfDay), + AirDateTime = GetDateTime(u.AirDate.Value, u.Series.AirTimes), AirDate = u.AirDate.Value.ToBestDateString(), - AirTime = Convert.ToDateTime(u.Series.AirTimes).ToShortTimeString(), + AirTime = String.IsNullOrEmpty(u.Series.AirTimes) ? "?" : Convert.ToDateTime(u.Series.AirTimes).ToShortTimeString(), Status = u.Status.ToString() }); @@ -80,9 +80,9 @@ public ActionResult _AjaxBindingTomorrow() EpisodeNumber = u.EpisodeNumber, Title = u.Title, Overview = u.Overview, - AirDateTime = u.AirDate.Value.Add(Convert.ToDateTime(u.Series.AirTimes).TimeOfDay), + AirDateTime = GetDateTime(u.AirDate.Value, u.Series.AirTimes), AirDate = u.AirDate.Value.ToBestDateString(), - AirTime = Convert.ToDateTime(u.Series.AirTimes).ToShortTimeString(), + AirTime = String.IsNullOrEmpty(u.Series.AirTimes) ? "?" : Convert.ToDateTime(u.Series.AirTimes).ToShortTimeString(), Status = u.Status.ToString() }); @@ -101,13 +101,21 @@ public ActionResult _AjaxBindingWeek() EpisodeNumber = u.EpisodeNumber, Title = u.Title, Overview = u.Overview, - AirDateTime = u.AirDate.Value.Add(Convert.ToDateTime(u.Series.AirTimes).TimeOfDay), + AirDateTime = GetDateTime(u.AirDate.Value, u.Series.AirTimes), AirDate = u.AirDate.Value.ToBestDateString(), - AirTime = Convert.ToDateTime(u.Series.AirTimes).ToShortTimeString(), + AirTime = String.IsNullOrEmpty(u.Series.AirTimes) ? "?" : Convert.ToDateTime(u.Series.AirTimes).ToShortTimeString(), Status = u.Status.ToString() }); return View(new GridModel(upcoming)); } + + private DateTime GetDateTime(DateTime airDate, string airTime) + { + if (String.IsNullOrWhiteSpace(airTime)) + return airDate; + + return airDate.Add(Convert.ToDateTime(airTime).TimeOfDay); + } } } \ No newline at end of file From c534d47b0aabadbf96b7c90cc0e63d2b8df3fcd0 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 10 Oct 2011 21:00:31 -0700 Subject: [PATCH 2/2] Added InheritFolderPermissions to DiskProvider. DiskScanProvider.MoveEpisode will now set the moved file to inherit the parent folder permissions. --- NzbDrone.Core/Providers/Core/DiskProvider.cs | 7 + NzbDrone.Core/Providers/DiskScanProvider.cs | 3 + NzbDrone/Providers/ConfigProvider.cs.orig | 228 ------------------- 3 files changed, 10 insertions(+), 228 deletions(-) delete mode 100644 NzbDrone/Providers/ConfigProvider.cs.orig diff --git a/NzbDrone.Core/Providers/Core/DiskProvider.cs b/NzbDrone.Core/Providers/Core/DiskProvider.cs index be81eebea..f93580af4 100644 --- a/NzbDrone.Core/Providers/Core/DiskProvider.cs +++ b/NzbDrone.Core/Providers/Core/DiskProvider.cs @@ -73,5 +73,12 @@ public virtual void MoveDirectory(string source, string destination) { Directory.Move(source, destination); } + + public virtual void InheritFolderPermissions(string filename) + { + var fs = File.GetAccessControl(filename); + fs.SetAccessRuleProtection(false, false); + File.SetAccessControl(filename, fs); + } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index 31737d3da..3348910f3 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -171,6 +171,9 @@ public virtual bool MoveEpisodeFile(EpisodeFile episodeFile, bool newDownload = Logger.Debug("Moving [{0}] > [{1}]", episodeFile.Path, newFile.FullName); _diskProvider.MoveFile(episodeFile.Path, newFile.FullName); + //Make the file inherit parent permissions + _diskProvider.InheritFolderPermissions(newFile.FullName); + //Update the filename in the DB episodeFile.Path = newFile.FullName; _mediaFileProvider.Update(episodeFile); diff --git a/NzbDrone/Providers/ConfigProvider.cs.orig b/NzbDrone/Providers/ConfigProvider.cs.orig deleted file mode 100644 index f1e6db1be..000000000 --- a/NzbDrone/Providers/ConfigProvider.cs.orig +++ /dev/null @@ -1,228 +0,0 @@ -using System; -using System.IO; -using System.Linq; -using System.Xml.Linq; -using System.Xml.XPath; -using NLog; -using NLog.Config; -<<<<<<< HEAD -using Ninject; -======= -using NzbDrone.Model; ->>>>>>> markus - -namespace NzbDrone.Providers -{ - public class ConfigProvider - { - private readonly EnviromentProvider _enviromentProvider; - private static readonly Logger Logger = LogManager.GetLogger("Host.ConfigProvider"); - - [Inject] - public ConfigProvider(EnviromentProvider enviromentProvider) - { - _enviromentProvider = enviromentProvider; - } - - public ConfigProvider() - { - - } - - public virtual int PortNumber - { - get { return GetValueInt("Port", 8989); } - } - - public virtual bool LaunchBrowser - { - get { return GetValueBoolean("LaunchBrowser", true); } - } - - public virtual string IISDirectory - { - get { return Path.Combine(_enviromentProvider.ApplicationPath, "IISExpress"); } - } - - public virtual string IISExePath - { - get { return Path.Combine(IISDirectory, "iisexpress.exe"); } - } - - public virtual string IISConfigPath - { - get { return Path.Combine(IISDirectory, "AppServer", "applicationhost.config"); } - } - - public virtual string AppDataDirectory - { - get { return Path.Combine(_enviromentProvider.ApplicationPath, "NzbDrone.Web", "App_Data"); } - } - - public virtual string ConfigFile - { - get { return Path.Combine(AppDataDirectory, "Config.xml"); } - } - - public virtual string NlogConfigPath - { - get { return Path.Combine(_enviromentProvider.ApplicationPath, "NzbDrone.Web\\log.config"); } - } - -<<<<<<< HEAD -======= - public virtual AuthenticationType AuthenticationType - { - get { return (AuthenticationType)GetValueInt("AuthenticationType", 0); } - set { SetValue("AuthenticationType", (int)value); } - } ->>>>>>> markus - - public virtual void ConfigureNlog() - { - LogManager.Configuration = new XmlLoggingConfiguration(NlogConfigPath, false); - } - - public virtual void UpdateIISConfig(string configPath) - { - Logger.Info(@"Server configuration file: {0}", configPath); - Logger.Info(@"Configuring server to: [http://localhost:{0}]", PortNumber); - - var configXml = XDocument.Load(configPath); - - var bindings = - configXml.XPathSelectElement("configuration/system.applicationHost/sites").Elements("site").Where( - d => d.Attribute("name").Value.ToLowerInvariant() == "nzbdrone").First().Element("bindings"); - bindings.Descendants().Remove(); - bindings.Add( - new XElement("binding", - new XAttribute("protocol", "http"), - new XAttribute("bindingInformation", String.Format("*:{0}:localhost", PortNumber)) - )); - - bindings.Add( - new XElement("binding", - new XAttribute("protocol", "http"), - new XAttribute("bindingInformation", String.Format("*:{0}:", PortNumber)) - )); - - //Update the authenticationTypes - - var location = configXml.XPathSelectElement("configuration").Elements("location").Where( - d => d.Attribute("path").Value.ToLowerInvariant() == "nzbdrone").First(); - - - var authenticationTypes = location.XPathSelectElements("system.webServer/security/authentication").First().Descendants(); - - //Set all authentication types enabled to false - foreach (var child in authenticationTypes) - { - child.Attribute("enabled").Value = "false"; - } - - var configuredAuthType = String.Format("{0}Authentication", AuthenticationType.ToString()).ToLowerInvariant(); - - //Set the users authenticationType to true - authenticationTypes.Where(t => t.Name.ToString().ToLowerInvariant() == configuredAuthType).Single().Attribute("enabled").Value = "true"; - - configXml.Save(configPath); - } - - public virtual void CreateDefaultConfigFile() - { - //Create the config file here - Directory.CreateDirectory(AppDataDirectory); - - if (!File.Exists(ConfigFile)) - { - WriteDefaultConfig(); - } - } - -<<<<<<< HEAD - private void WriteDefaultConfig() -======= - public virtual string GetValue(string key, object defaultValue, string parent = null) ->>>>>>> markus - { - var xDoc = XDocument.Load(ConfigFile); - var config = xDoc.Descendants("Config").Single(); - - var parentContainer = config; - - if (!String.IsNullOrEmpty(parent)) - { - //Add the parent - if (config.Descendants(parent).Count() != 1) - { - SetValue(key, defaultValue, parent); - - //Reload the configFile - xDoc = XDocument.Load(ConfigFile); - config = xDoc.Descendants("Config").Single(); - } - - parentContainer = config.Descendants(parent).Single(); - } - - var valueHolder = parentContainer.Descendants(key).ToList(); - - if (valueHolder.Count() == 1) - return valueHolder.First().Value; - - //Save the value - SetValue(key, defaultValue, parent); - - //return the default value - return defaultValue.ToString(); - } - - public virtual int GetValueInt(string key, int defaultValue, string parent = null) - { - return Convert.ToInt32(GetValue(key, defaultValue, parent)); - } - - public virtual bool GetValueBoolean(string key, bool defaultValue, string parent = null) - { - return Convert.ToBoolean(GetValue(key, defaultValue, parent)); - } - - public virtual void SetValue(string key, object value, string parent = null) - { - var xDoc = XDocument.Load(ConfigFile); - var config = xDoc.Descendants("Config").Single(); - - var parentContainer = config; - - if (!String.IsNullOrEmpty(parent)) - { - //Add the parent container if it doesn't already exist - if (config.Descendants(parent).Count() != 1) - { - config.Add(new XElement(parent)); - } - - parentContainer = config.Descendants(parent).Single(); - } - - var keyHolder = parentContainer.Descendants(key); - - if (keyHolder.Count() != 1) - parentContainer.Add(new XElement(key, value)); - - else - parentContainer.Descendants(key).Single().Value = value.ToString(); - - xDoc.Save(ConfigFile); - } - - public virtual void WriteDefaultConfig() - { - var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); - - xDoc.Add(new XElement("Config")); - - xDoc.Save(ConfigFile); - } - } -} \ No newline at end of file