Skip to content

Commit 25c701c

Browse files
authored
LMDB: introduce a typealias for mode_t (#600)
`mode_t` is a non-portable extension to C (POSIX). Introduce a new typealias `ModeType` that represents the underlying type that is used. Provide an alternate definition for the default mode on Windows as it does not have non-user permissions on a file but rather relies on proper ACLing.
1 parent 483297f commit 25c701c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Sources/SwiftDocC/Utility/LMDB/LMDB+Environment.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ extension LMDB {
5454
- maxDBs: The maximum number of databases that can be opened in the environment. Default: infinite.
5555
- maxReaders: The maximum number of readers to use. Default: 126
5656
- mapSize: The size of the map on disk in bytes. Default: 10 MB.
57-
- fileMode: The `mode_t` to use when opening a file for the database. Default: 744.
57+
- fileMode: The `LMDB.ModeType` to use when opening a file for the database. Default: 744.
5858

5959
- Throws: An error if the environment can't be initialized correctly.
6060
*/
61-
public init(path: String, flags: Flags = [], maxDBs: UInt32 = LMDB.defaultMaxDBs, maxReaders: UInt32 = LMDB.defaultMaxReaders, mapSize: size_t = LMDB.defaultMapSize, fileMode: mode_t = LMDB.defaultFileMode) throws {
61+
public init(path: String, flags: Flags = [], maxDBs: UInt32 = LMDB.defaultMaxDBs, maxReaders: UInt32 = LMDB.defaultMaxReaders, mapSize: size_t = LMDB.defaultMapSize, fileMode: LMDB.ModeType = LMDB.defaultFileMode) throws {
6262

6363
let result = mdb_env_create(&opaquePointer)
6464
guard result == 0 else {
@@ -91,7 +91,7 @@ extension LMDB {
9191
}
9292
}
9393

94-
private func configureEnvironment(opaquePointer: OpaquePointer? = nil, maxDBs: UInt32 = LMDB.defaultMaxDBs, maxReaders: UInt32 = LMDB.defaultMaxReaders, mapSize: size_t = LMDB.defaultMapSize, fileMode: mode_t = LMDB.defaultFileMode) throws {
94+
private func configureEnvironment(opaquePointer: OpaquePointer? = nil, maxDBs: UInt32 = LMDB.defaultMaxDBs, maxReaders: UInt32 = LMDB.defaultMaxReaders, mapSize: size_t = LMDB.defaultMapSize, fileMode: LMDB.ModeType = LMDB.defaultFileMode) throws {
9595

9696
if maxDBs != LMDB.defaultMaxDBs {
9797
let returnCode = mdb_env_set_maxdbs(opaquePointer, MDB_dbi(maxDBs))

Sources/SwiftDocC/Utility/LMDB/LMDB.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import CLMDB
1818
Reads are never blocked, but writes are serialized using a mutually exclusive lock at the database level.
1919
*/
2020
final class LMDB {
21+
#if os(Windows)
22+
public typealias ModeType = CInt
23+
#else
24+
public typealias ModeType = mode_t
25+
#endif
2126

2227
/// Default instance.
2328
public static var `default` = LMDB()
@@ -37,7 +42,11 @@ final class LMDB {
3742
public static let defaultMapSize: size_t = 10485760
3843

3944
/// The default file mode for opening an environment which is `744`.
40-
public static let defaultFileMode: mode_t = S_IRWXU | S_IRGRP | S_IROTH
45+
#if os(Windows)
46+
public static let defaultFileMode: ModeType = _S_IREAD | _S_IWRITE
47+
#else
48+
public static let defaultFileMode: ModeType = S_IRWXU | S_IRGRP | S_IROTH
49+
#endif
4150

4251
}
4352

0 commit comments

Comments
 (0)