Skip to content

Commit

Permalink
Check intermediate paths in OnRenamed for null
Browse files Browse the repository at this point in the history
It appears that Pri.LongPath.GetDirectoryName or Pri.LongPath.GetFileName
can sometimes return null. I'm not sure why... But let's not crash
in this case

Relates to #112
  • Loading branch information
canton7 committed Jun 16, 2015
1 parent e09c57b commit d986867
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
20 changes: 19 additions & 1 deletion src/SyncTrayzor/Services/DirectoryWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,25 @@ private void OnRenamed(object source, RenamedEventArgs e)
// So, construct it from e.FullPath and e.OldName
// Note that we're using Pri.LongPath to get a Path.GetDirectoryName implementation that can handle
// long paths
var oldFullPath = Path.Combine(Path.GetDirectoryName(e.FullPath), Path.GetFileName(e.OldName));

// Apparently Path.GetDirectoryName(e.FullPath) or Path.GetFileName(e.OldName) can return null, see #112
// Not sure why this might be, but let's work around it...
var oldFullPathDirectory = Path.GetDirectoryName(e.FullPath);
var oldFileName = Path.GetFileName(e.OldName);

if (oldFullPathDirectory == null)
{
logger.Warn("OldFullPathDirectory is null. Not sure why... e.FullPath: {0}", e.FullPath);
return;
}

if (oldFileName == null)
{
logger.Warn("OldFileName is null. Not sure why... e.OldName: {0}", e.OldName);
return;
}

var oldFullPath = Path.Combine(oldFullPathDirectory, oldFileName);

this.PathChanged(oldFullPath, fileExists: false);
}
Expand Down
18 changes: 6 additions & 12 deletions src/SyncTrayzor/SyncThing/ApiClient/LocalIndexUpdatedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@ namespace SyncTrayzor.SyncThing.ApiClient
{
public class LocalIndexUpdatedEventData
{
[JsonProperty("flags")]
public string Flags { get; set; }

[JsonProperty("modified")]
public DateTime Modified { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("folder")]
public string Folder { get; set; }

[JsonProperty("size")]
public long Size { get; set; }
[JsonProperty("items")]
public int Items { get; set; }

[JsonProperty("version")]
public long Version { get; set; }
}

public class LocalIndexUpdatedEvent : Event
Expand All @@ -37,7 +31,7 @@ public override void Visit(IEventVisitor visitor)

public override string ToString()
{
return String.Format("<LocalIndexUpdated ID={0} Time={1} Flags={2} Modified={3} Name={4} Folder={5} Size={6}>", this.Id, this.Time, this.Data.Flags, this.Data.Modified, this.Data.Name, this.Data.Folder, this.Data.Size);
return String.Format("<LocalIndexUpdated ID={0} Time={1} Folder={2} Items={3} Version={4}>", this.Id, this.Time, this.Data.Folder, this.Data.Items, this.Data.Version);
}
}
}
6 changes: 5 additions & 1 deletion src/SyncTrayzor/SyncThing/ApiClient/StartupCompleteEvent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -8,6 +9,9 @@ namespace SyncTrayzor.SyncThing.ApiClient
{
public class StartupCompleteEvent : Event
{
[JsonProperty("myID")]
public string MyID { get; set; }

public override void Visit(IEventVisitor visitor)
{
visitor.Accept(this);
Expand Down

0 comments on commit d986867

Please sign in to comment.