Skip to content

Commit 6f3d507

Browse files
committed
Changed file opening access mode in C# and updated data directory searching for Java and C#
1 parent 4f5e778 commit 6f3d507

File tree

10 files changed

+39
-8
lines changed

10 files changed

+39
-8
lines changed

csharp/runner/SnippetRunner/InstallLocations.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,22 @@ private static bool IsDirectory(string path)
302302
}
303303
else
304304
{
305+
switch (Environment.OSVersion.Platform)
306+
{
307+
case PlatformID.Win32NT:
308+
defaultSupportPath = Path.Combine(installDir.FullName, "data");
309+
break;
310+
case PlatformID.MacOSX:
311+
defaultSupportPath = Path.Combine(installDir.FullName, "data");
312+
break;
313+
case PlatformID.Unix:
314+
break;
315+
default:
316+
throw new NotSupportedException(
317+
"Unsupported Operating System: "
318+
+ Environment.OSVersion.Platform);
319+
}
320+
305321
// no explicit path, try the default support path
306322
supportDir = new DirectoryInfo(defaultSupportPath);
307323
}

csharp/snippets/deleting/DeleteViaFutures/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ TaskScheduler taskScheduler
159159
}
160160
finally
161161
{
162+
fs.Close();
163+
162164
// IMPORTANT: make sure to destroy the environment
163165
env.Destroy();
164166

csharp/snippets/deleting/DeleteViaLoop/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@
130130
}
131131
finally
132132
{
133+
fs.Close();
134+
133135
// IMPORTANT: make sure to destroy the environment
134136
env.Destroy();
135137

csharp/snippets/deleting/DeleteWithInfoViaFutures/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ TaskScheduler taskScheduler
160160
}
161161
finally
162162
{
163+
fs.Close();
164+
163165
// IMPORTANT: make sure to destroy the environment
164166
env.Destroy();
165167

csharp/snippets/loading/LoadViaFutures/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ TaskScheduler taskScheduler
4949
// keep track of the pending tasks and don't backlog too many for memory's sake
5050
IList<(Task, Record)> pendingFutures = new List<(Task, Record)>(MaximumBacklog);
5151

52-
FileStream fs = new FileStream(filePath, FileMode.Open);
52+
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
5353
try
5454
{
5555
// create a reader
@@ -159,6 +159,9 @@ TaskScheduler taskScheduler
159159
}
160160
finally
161161
{
162+
// close the file stream
163+
fs.Close();
164+
162165
// IMPORTANT: make sure to destroy the environment
163166
env.Destroy();
164167

csharp/snippets/loading/LoadViaLoop/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
string filePath = (args.Length > 0) ? args[0] : DefaultFilePath;
3333

34-
FileStream fs = new FileStream(filePath, FileMode.Open);
34+
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
3535
try
3636
{
3737
// create a reader
@@ -131,7 +131,7 @@
131131
finally
132132
{
133133
fs.Close();
134-
134+
135135
// IMPORTANT: make sure to destroy the environment
136136
env.Destroy();
137137

csharp/snippets/loading/LoadViaQueue/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@
3232

3333
string filePath = (args.Length > 0) ? args[0] : DefaultFilePath;
3434

35-
FileStream fs = new FileStream(filePath, FileMode.Open);
3635
Thread producer = new Thread(() =>
3736
{
38-
FileStream fs = new FileStream(filePath, FileMode.Open);
37+
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
3938
try
4039
{
4140
StreamReader rdr = new StreamReader(fs, Encoding.UTF8);
@@ -71,6 +70,7 @@
7170
}
7271
finally
7372
{
73+
fs.Close();
7474
recordQueue.CompleteAdding();
7575
}
7676
});

csharp/snippets/loading/LoadWithInfoViaFutures/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ TaskScheduler taskScheduler
5050
IList<(Task<string>, Record)> pendingFutures
5151
= new List<(Task<string>, Record)>(MaximumBacklog);
5252

53-
FileStream fs = new FileStream(filePath, FileMode.Open);
53+
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
5454
try
5555
{
5656
// create a reader
@@ -161,6 +161,8 @@ TaskScheduler taskScheduler
161161
}
162162
finally
163163
{
164+
fs.Close();
165+
164166
// IMPORTANT: make sure to destroy the environment
165167
env.Destroy();
166168

csharp/snippets/loading/LoadWithStatsViaLoop/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
string filePath = (args.Length > 0) ? args[0] : DefaultFilePath;
3333

34-
FileStream fs = new FileStream(filePath, FileMode.Open);
34+
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
3535
try
3636
{
3737
// create a reader
@@ -151,6 +151,8 @@
151151
}
152152
finally
153153
{
154+
fs.Close();
155+
154156
// IMPORTANT: make sure to destroy the environment
155157
env.Destroy();
156158

java/runner/java/com/senzing/runner/InstallLocations.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,11 @@ public static InstallLocations findLocations() {
256256
if ("dist".equals(installDir.getName())) {
257257
// use the "data" sub-directory of the dev build
258258
supportDir = new File(installDir, "data");
259+
} else if (windows || macOS) {
260+
supportDir = new File(installDir, "data");
259261
} else {
260262
// no explicit path, try the default support path
261-
supportDir = new File(defaultSupportPath);
263+
supportDir = new File(defaultSupportPath);
262264
}
263265

264266
} else {

0 commit comments

Comments
 (0)