Skip to content

Commit b98bf5c

Browse files
authored
Merge pull request #103 from msallin/#97
#97 Copy file attributes when recreating db file.
2 parents 7f17c58 + 4f95446 commit b98bf5c

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

SQLite.CodeFirst/Internal/Utility/InMemoryAwareFile.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ namespace SQLite.CodeFirst.Utility
55
{
66
internal class InMemoryAwareFile
77
{
8+
public static FileAttributes? GetFileAttributes(string path)
9+
{
10+
if (IsInMemoryPath(path))
11+
{
12+
return null;
13+
}
14+
return File.GetAttributes(path);
15+
}
16+
17+
public static void SetFileAttributes(string path, FileAttributes? fileAttributes)
18+
{
19+
if (IsInMemoryPath(path) || fileAttributes == null)
20+
{
21+
return;
22+
}
23+
File.SetAttributes(path, fileAttributes.Value);
24+
}
25+
826
public static bool Exists(string path)
927
{
1028
if (IsInMemoryPath(path))

SQLite.CodeFirst/Public/DbInitializers/SqliteDropCreateDatabaseAlways.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ public override void InitializeDatabase(TContext context)
3434
bool exists = InMemoryAwareFile.Exists(databseFilePath);
3535
if (exists)
3636
{
37+
FileAttributes? attributes = InMemoryAwareFile.GetFileAttributes(databseFilePath);
3738
InMemoryAwareFile.Delete(databseFilePath);
39+
base.InitializeDatabase(context);
40+
InMemoryAwareFile.SetFileAttributes(databseFilePath, attributes);
41+
}
42+
else
43+
{
44+
base.InitializeDatabase(context);
3845
}
39-
40-
base.InitializeDatabase(context);
4146
}
4247
}
4348
}

SQLite.CodeFirst/Public/DbInitializers/SqliteDropCreateDatabaseWhenModelChanges.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,18 @@ public override void InitializeDatabase(TContext context)
7070
{
7171
string databseFilePath = GetDatabasePathFromContext(context);
7272

73-
bool dbExists = File.Exists(databseFilePath);
73+
bool dbExists = InMemoryAwareFile.Exists(databseFilePath);
7474
if (dbExists)
7575
{
7676
if (IsSameModel(context))
7777
{
7878
return;
7979
}
8080

81+
FileAttributes? attributes = InMemoryAwareFile.GetFileAttributes(databseFilePath);
8182
DeleteDatabase(context, databseFilePath);
8283
base.InitializeDatabase(context);
84+
InMemoryAwareFile.SetFileAttributes(databseFilePath, attributes);
8385
SaveHistory(context);
8486
}
8587
else

0 commit comments

Comments
 (0)