I'm trying to create a SQLite file setting the permission full for everyone. I've tried the following:
class StudioContext : DbContext
{
public IDbSet<PinnedCommand> Pinned { get; set; }
public StudioContext()
: this(Constants.StudioDataFilePath)
{
}
private StudioContext(string databasePath)
: base(GetConnection(databasePath), true)
{
Configuration.ProxyCreationEnabled = false;
}
private static DbConnection GetConnection(string databasePath)
{
var dir = new DirectoryInfo(Path.GetDirectoryName(databasePath));
if (!dir.Exists)
dir.Create();
GrantFullPermission(databasePath);
var connSb = new SQLiteConnectionStringBuilder()
{
DataSource = databasePath,
ForeignKeys = true,
BinaryGUID = true,
DateTimeFormat = SQLiteDateFormats.ISO8601,
DateTimeKind = DateTimeKind.Utc
};
return new SQLiteConnection(connSb.ConnectionString);
}
private static void GrantFullPermission(string databasePath)
{
if (File.Exists(databasePath))
return;
var rule = new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.FullControl, AccessControlType.Allow);
var security = new FileSecurity();
security.AddAccessRule(rule);
using (File.Create(databasePath, 100, FileOptions.None, security))
{
}
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
Database.SetInitializer(new SqliteDropCreateDatabaseWhenModelChanges<StudioContext>(modelBuilder));
}
The file is created with full permission, however right after its creation, SQLite overrides it and the permission rules are lost.
How can I create the database file with permission rules set?