Skip to content

Commit 982a771

Browse files
committed
Fixed an issue with storage file paths not working properly on linux / osx.
1 parent deb484d commit 982a771

File tree

11 files changed

+41
-26
lines changed

11 files changed

+41
-26
lines changed

appveyor.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ configuration: Release
66
pull_requests:
77
do_not_increment_build_number: true
88

9-
#environment:
10-
# VERSION_SUFFIX: -preview
9+
environment:
10+
VERSION_SUFFIX: -beta
1111

1212
init:
1313
- git config --global core.autocrlf true

src/Exceptionless.Tests/Configuration/ConfigurationTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using Exceptionless.Configuration;
45
using Exceptionless.Dependency;
56
using Exceptionless.Models;
@@ -86,8 +87,9 @@ public void CanUpdateSettingsFromServer() {
8687
Assert.Equal(3, client.Configuration.Settings.Count);
8788

8889
var storage = config.Resolver.GetFileStorage() as InMemoryObjectStorage;
90+
Assert.NotNull(storage);
8991
Assert.NotNull(config.GetQueueName());
90-
Assert.True(storage.Exists(config.GetQueueName() + "\\server-settings.json"));
92+
Assert.True(storage.Exists(Path.Combine(config.GetQueueName(), "server-settings.json")));
9193

9294
config.Settings.Clear();
9395
config.ApplySavedServerSettings();

src/Exceptionless.Tests/Storage/FileStorageTestsBase.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.Diagnostics;
5+
using System.IO;
56
using System.Linq;
67
using System.Threading;
78
using System.Threading.Tasks;
@@ -32,8 +33,8 @@ public void CanManageFiles() {
3233
Assert.True(storage.GetObjectList().Any(f => f.Path == "new.txt"));
3334
storage.DeleteObject("new.txt");
3435
Assert.Equal(0, storage.GetObjectList().Count());
35-
storage.SaveObject("test\\q\\" + Guid.NewGuid().ToString("N") + ".txt", "test");
36-
Assert.Equal(1, storage.GetObjectList("test\\q\\*.txt").Count());
36+
storage.SaveObject(Path.Combine("test", "q", Guid.NewGuid().ToString("N") + ".txt"), "test");
37+
Assert.Equal(1, storage.GetObjectList(Path.Combine("test","q", "*.txt")).Count());
3738
Assert.Equal(1, storage.GetObjectList("*", null, DateTime.Now).Count());
3839
List<ObjectInfo> files = storage.GetObjectList("*", null, DateTime.Now.Subtract(TimeSpan.FromMinutes(5))).ToList();
3940
Debug.WriteLine(String.Join(",", files.Select(f => f.Path + " " + f.Created)));
@@ -51,7 +52,7 @@ public void CanManageQueue() {
5152
var ev = new Event { Type = Event.KnownTypes.Log, Message = "test" };
5253
storage.Enqueue(queueName, ev);
5354
storage.SaveObject("test.txt", "test");
54-
Assert.True(storage.GetObjectList().Any(f => f.Path.StartsWith(queueName + "\\q\\") && f.Path.EndsWith("0.json")));
55+
Assert.True(storage.GetObjectList().Any(f => f.Path.StartsWith(Path.Combine(queueName, "q")) && f.Path.EndsWith("0.json")));
5556
Assert.Equal(2, storage.GetObjectList().Count());
5657

5758
Assert.True(storage.GetQueueFiles(queueName).All(f => f.Path.EndsWith("0.json")));
@@ -67,7 +68,7 @@ public void CanManageQueue() {
6768
var batch = storage.GetEventBatch(queueName, serializer);
6869
Assert.Equal(1, batch.Count);
6970

70-
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(queueName + "\\q\\") && f.Path.EndsWith("1.json.x")));
71+
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(Path.Combine(queueName, "q")) && f.Path.EndsWith("1.json.x")));
7172
Assert.Equal(1, storage.GetObjectList().Count());
7273

7374
Assert.Equal(0, storage.GetQueueFiles(queueName).Count());
@@ -76,26 +77,26 @@ public void CanManageQueue() {
7677
Assert.False(storage.LockFile(storage.GetObjectList().FirstOrDefault()));
7778

7879
storage.ReleaseBatch(batch);
79-
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(queueName + "\\q\\") && f.Path.EndsWith("1.json")));
80+
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(Path.Combine(queueName, "q")) && f.Path.EndsWith("1.json")));
8081
Assert.Equal(1, storage.GetObjectList().Count());
8182
Assert.Equal(1, storage.GetQueueFiles(queueName).Count());
8283

8384
var file = storage.GetObjectList().FirstOrDefault();
8485
storage.IncrementAttempts(file);
85-
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(queueName + "\\q\\") && f.Path.EndsWith("2.json")));
86+
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(Path.Combine(queueName, "q")) && f.Path.EndsWith("2.json")));
8687
storage.IncrementAttempts(file);
87-
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(queueName + "\\q\\") && f.Path.EndsWith("3.json")));
88+
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(Path.Combine(queueName, "q")) && f.Path.EndsWith("3.json")));
8889

8990
Assert.True(storage.LockFile(file));
9091
Assert.NotNull(file);
91-
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(queueName + "\\q\\") && f.Path.EndsWith("3.json.x")));
92+
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(Path.Combine(queueName, "q")) && f.Path.EndsWith("3.json.x")));
9293
Thread.Sleep(TimeSpan.FromMilliseconds(1));
9394
storage.ReleaseStaleLocks(queueName, TimeSpan.Zero);
94-
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(queueName + "\\q\\") && f.Path.EndsWith("3.json")));
95+
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(Path.Combine(queueName, "q")) && f.Path.EndsWith("3.json")));
9596

9697
batch = storage.GetEventBatch(queueName, serializer);
9798
Assert.Equal(1, batch.Count);
98-
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(queueName + "\\q\\") && f.Path.EndsWith("4.json.x")));
99+
Assert.True(storage.GetObjectList().All(f => f.Path.StartsWith(Path.Combine(queueName, "q")) && f.Path.EndsWith("4.json.x")));
99100
storage.DeleteBatch(batch);
100101
Assert.Equal(0, storage.GetQueueFiles(queueName).Count());
101102

src/Exceptionless.Tests/Storage/FolderFileStorageTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using Xunit;
34
using Exceptionless.Dependency;
45
using Exceptionless.Serializer;
@@ -22,7 +23,7 @@ public void CanUseDataDirectory() {
2223
var storage = new FolderObjectStorage(resolver, DATA_DIRECTORY_QUEUE_FOLDER);
2324
Assert.NotNull(storage.Folder);
2425
Assert.NotEqual(DATA_DIRECTORY_QUEUE_FOLDER, storage.Folder);
25-
Assert.True(storage.Folder.EndsWith("Queue\\"), storage.Folder);
26+
Assert.True(storage.Folder.EndsWith("Queue" + Path.DirectorySeparatorChar) || storage.Folder.EndsWith("Queue" + Path.AltDirectorySeparatorChar), storage.Folder);
2627
}
2728
}
2829
}

src/Exceptionless.Tests/project.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
"xunit.runner.visualstudio": "2.1.0"
2727
},
2828
"frameworks": {
29-
"net46": {
29+
"NET46": {
30+
"buildOptions": {
31+
"define": [ "NET46" ]
32+
},
3033
"frameworkAssemblies": {
3134
"System.Threading.Tasks": "",
3235
"System.Runtime": ""

src/Exceptionless/Configuration/SettingsManager.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.IO;
23
using System.Linq;
34
using Exceptionless.Dependency;
45
using Exceptionless.Logging;
@@ -103,7 +104,8 @@ public static void UpdateSettings(ExceptionlessConfiguration config, int? versio
103104
}
104105

105106
private static string GetConfigPath(ExceptionlessConfiguration config) {
106-
return (config != null ? config.GetQueueName() : String.Empty) + "\\server-settings.json";
107+
string queueName = config != null ? config.GetQueueName() : String.Empty;
108+
return Path.Combine(queueName ?? String.Empty, "server-settings.json");
107109
}
108110
}
109111
}

src/Exceptionless/Extensions/FileStorageExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using Exceptionless.Models;
56
using Exceptionless.Storage;
@@ -9,14 +10,14 @@ public static class FileStorageExtensions {
910
private static readonly object _lockObject = new object();
1011

1112
public static void Enqueue(this IObjectStorage storage, string queueName, Event ev) {
12-
storage.SaveObject(String.Concat(queueName, "\\q\\", Guid.NewGuid().ToString("N"), ".0.json"), ev);
13+
storage.SaveObject(Path.Combine(queueName, "q", Guid.NewGuid().ToString("N") + ".0.json"), ev);
1314
}
1415

1516
public static void CleanupQueueFiles(this IObjectStorage storage, string queueName, TimeSpan? maxAge = null, int? maxAttempts = null) {
1617
maxAge = maxAge ?? TimeSpan.FromDays(7);
1718
maxAttempts = maxAttempts ?? 3;
1819

19-
foreach (var file in storage.GetObjectList(queueName + "\\q\\*", 500).ToList()) {
20+
foreach (var file in storage.GetObjectList(Path.Combine(queueName, "q", "*"), 500).ToList()) {
2021
if (DateTime.Now.Subtract(file.Created) > maxAge.Value)
2122
storage.DeleteObject(file.Path);
2223
if (GetAttempts(file) >= maxAttempts.Value)
@@ -25,7 +26,7 @@ public static void CleanupQueueFiles(this IObjectStorage storage, string queueNa
2526
}
2627

2728
public static ICollection<ObjectInfo> GetQueueFiles(this IObjectStorage storage, string queueName, int? limit = null, DateTime? maxCreatedDate = null) {
28-
return storage.GetObjectList(queueName + "\\q\\*.json", limit, maxCreatedDate).OrderByDescending(f => f.Created).ToList();
29+
return storage.GetObjectList(Path.Combine(queueName, "q", "*.json"), limit, maxCreatedDate).OrderByDescending(f => f.Created).ToList();
2930
}
3031

3132
public static bool IncrementAttempts(this IObjectStorage storage, ObjectInfo info) {
@@ -89,7 +90,7 @@ public static void ReleaseStaleLocks(this IObjectStorage storage, string queueNa
8990
if (!maxLockAge.HasValue)
9091
maxLockAge = TimeSpan.FromMinutes(60);
9192

92-
foreach (var file in storage.GetObjectList(queueName + "\\q\\*.x", 500).ToList().Where(f => f.Modified < DateTime.Now.Subtract(maxLockAge.Value)))
93+
foreach (var file in storage.GetObjectList(Path.Combine(queueName, "q", "*.x"), 500).ToList().Where(f => f.Modified < DateTime.Now.Subtract(maxLockAge.Value)))
9394
storage.ReleaseFile(file);
9495
}
9596

src/Exceptionless/Storage/FolderObjectStorage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public FolderObjectStorage(IDependencyResolver resolver, string folder) {
1818

1919
if (!Path.IsPathRooted(folder))
2020
folder = Path.GetFullPath(folder);
21-
if (!folder.EndsWith("\\"))
22-
folder += "\\";
21+
if (!folder.EndsWith(Path.DirectorySeparatorChar.ToString()) && !folder.EndsWith(Path.AltDirectorySeparatorChar.ToString()))
22+
folder += Path.DirectorySeparatorChar;
2323

2424
Folder = folder;
2525

src/Exceptionless/Storage/InMemoryObjectStorage.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ public IEnumerable<ObjectInfo> GetObjectList(string searchPattern = null, int? l
9494
if (!maxCreatedDate.HasValue)
9595
maxCreatedDate = DateTime.MaxValue;
9696

97-
var regex = new Regex("^" + Regex.Escape(searchPattern).Replace("\\*", ".*?") + "$");
97+
98+
#if PORTABLE || NETSTANDARD1_2
99+
var regex = new Regex("^" + Regex.Escape(searchPattern).Replace("\\*", ".*?").Replace("/*", ".*?") + "$");
100+
#else
101+
var regex = new Regex("^" + Regex.Escape(searchPattern).Replace(Path.DirectorySeparatorChar + "*", ".*?").Replace(Path.AltDirectorySeparatorChar + "*", ".*?") + "$");
102+
#endif
98103
lock (_lock)
99104
return _storage.Keys.Where(k => regex.IsMatch(k)).Select(k => _storage[k].Item1).Where(f => f.Created <= maxCreatedDate).Take(limit ?? Int32.MaxValue).ToList();
100105
}

src/Exceptionless/Storage/IsolatedStorageObjectStorage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public IEnumerable<string> GetObjects(string searchPattern = null, int? limit =
3737
stack.Push(initialDirectory);
3838
Regex searchPatternRegex = null;
3939
if (!String.IsNullOrEmpty(searchPattern))
40-
searchPatternRegex = new Regex("^" + Regex.Escape(searchPattern).Replace("\\*", ".*?") + "$");
40+
searchPatternRegex = new Regex("^" + Regex.Escape(searchPattern).Replace(Path.DirectorySeparatorChar + "*", ".*?").Replace(Path.AltDirectorySeparatorChar + "*", ".*?") + "$");
4141

4242
while (stack.Count > 0) {
4343
string dir = stack.Pop();

0 commit comments

Comments
 (0)