@capacitor-community/sqlite 3.3.1 → 3.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## 3.3.2 (2021-12-13)
2
+
3
+ ### Chore
4
+
5
+ - Update to @capacitor/core 3.3.2
6
+ - Update to @capacitor/ios 3.3.2
7
+ - Update to @capacitor/android 3.3.2
8
+
9
+ ### Bug Fixes
10
+
11
+ - fix addSQLiteSuffix skips databases without .db extension issue#200
12
+
1
13
  ## 3.3.1 (2021-11-25)
2
14
 
3
15
  ### Chore
@@ -43,17 +43,28 @@ public class UtilsMigrate {
43
43
  throw new Exception("Folder " + dir + " no database files");
44
44
  }
45
45
  for (String file : listFiles) {
46
- if (uFile.getFileExtension((file)).equals("db")) {
47
- if (!file.contains("SQLite.db")) {
46
+ if (!file.contains("SQLite.db")) {
47
+ String fromFile = file;
48
+ String toFile = "";
49
+ if (dbList.size() > 0) {
48
50
  if (dbList.contains(file)) {
49
- String fromFile = file;
50
- String toFile = file.replace(".db", "SQLite.db");
51
- boolean ret = uFile.copyFromNames(context, pathFiles, fromFile, pathDB, toFile);
52
- if (!ret) {
53
- String msg = "Failed in copy " + fromFile + " to " + file;
54
- throw new Exception(msg);
51
+ if (uFile.getFileExtension((file)).equals("db")) {
52
+ toFile = file.replace(".db", "SQLite.db");
53
+ } else {
54
+ toFile = file.concat("SQLite.db");
55
55
  }
56
56
  }
57
+ } else {
58
+ if (uFile.getFileExtension((file)).equals("db")) {
59
+ toFile = file.replace(".db", "SQLite.db");
60
+ }
61
+ }
62
+ if (toFile.length() > 0) {
63
+ boolean ret = uFile.copyFromNames(context, pathFiles, fromFile, pathDB, toFile);
64
+ if (!ret) {
65
+ String msg = "Failed in copy " + fromFile + " to " + file;
66
+ throw new Exception(msg);
67
+ }
57
68
  }
58
69
  }
59
70
  }
@@ -89,14 +100,22 @@ public class UtilsMigrate {
89
100
  }
90
101
  String[] listFiles = dir.list();
91
102
  for (String file : listFiles) {
92
- if (uFile.getFileExtension((file)).equals("db")) {
93
- if (!file.contains("SQLite.db")) {
103
+ String delFile = "";
104
+ if (!file.contains("SQLite.db")) {
105
+ if (dbList.size() > 0) {
94
106
  if (dbList.contains(file)) {
95
- boolean ret = uFile.deleteFile(pathFiles, file);
96
- if (!ret) {
97
- String msg = "Failed in delete " + file;
98
- throw new Exception(msg);
99
- }
107
+ delFile = file;
108
+ }
109
+ } else {
110
+ if (uFile.getFileExtension((file)).equals("db")) {
111
+ delFile = file;
112
+ }
113
+ }
114
+ if (delFile.length() > 0) {
115
+ boolean ret = uFile.deleteFile(pathFiles, delFile);
116
+ if (!ret) {
117
+ String msg = "Failed in delete " + delFile;
118
+ throw new Exception(msg);
100
119
  }
101
120
  }
102
121
  }
@@ -180,17 +180,24 @@ class UtilsFile {
180
180
 
181
181
  // MARK: - GetFileList
182
182
 
183
- class func getFileList(path: String, ext: String) throws -> [String] {
183
+ class func getFileList(path: String, ext: String? = nil) throws -> [String] {
184
+
184
185
  do {
185
- var dbs: [String] = []
186
+ var files: [String] = []
186
187
  let filenames = try FileManager.default
187
188
  .contentsOfDirectory(atPath: path)
188
189
  for file in filenames {
189
- if file.hasSuffix(ext) {
190
- dbs.append(file)
190
+ if let mExtension = ext {
191
+ if file.hasSuffix(mExtension) {
192
+ files.append(file)
193
+ }
194
+ } else {
195
+ if file.prefix(1) != "." {
196
+ files.append(file)
197
+ }
191
198
  }
192
199
  }
193
- return dbs
200
+ return files
194
201
  } catch let error {
195
202
  print("Error: \(error)")
196
203
  throw UtilsFileError.getFileListFailed
@@ -14,7 +14,7 @@ enum UtilsMigrateError: Error {
14
14
 
15
15
  class UtilsMigrate {
16
16
 
17
- // MARK: - addSQLiteSuffix
17
+ // MARK: - getMigratableList
18
18
 
19
19
  class func getMigratableList(folderPath: String) throws -> [String] {
20
20
  var mDbList: [String] = []
@@ -25,7 +25,7 @@ class UtilsMigrate {
25
25
  if FileManager.default.fileExists(atPath: dbPathURL.relativePath,
26
26
  isDirectory: &isDir) &&
27
27
  isDir.boolValue {
28
- mDbList = try UtilsFile.getFileList(path: dbPathURL.relativePath, ext: ".db")
28
+ mDbList = try UtilsFile.getFileList(path: dbPathURL.relativePath, ext: nil)
29
29
 
30
30
  return mDbList
31
31
  } else {
@@ -47,7 +47,9 @@ class UtilsMigrate {
47
47
  }
48
48
 
49
49
  // MARK: - addSQLiteSuffix
50
+
50
51
  // swiftlint:disable function_body_length
52
+ // swiftlint:disable cyclomatic_complexity
51
53
  class func addSQLiteSuffix(folderPath: String, dbList: [String]) throws {
52
54
  var fromFile: String = ""
53
55
  var toFile: String = ""
@@ -59,12 +61,32 @@ class UtilsMigrate {
59
61
  if FileManager.default.fileExists(atPath: dbPathURL.relativePath,
60
62
  isDirectory: &isDir) &&
61
63
  isDir.boolValue {
62
- let mDbList: [String] = try UtilsFile
63
- .getFileList(path: dbPathURL.relativePath, ext: ".db")
64
+ var mDbList: [String]
65
+ if dbList.count > 0 {
66
+ mDbList = try UtilsFile
67
+ .getFileList(path: dbPathURL.relativePath, ext: nil)
68
+ } else {
69
+ mDbList = try UtilsFile
70
+ .getFileList(path: dbPathURL.relativePath, ext: "db")
71
+ }
64
72
  for file: String in mDbList {
65
73
  if !file.contains("SQLite.db") {
66
74
  fromFile = file
67
- if dbList.contains(fromFile) {
75
+ if dbList.count > 0 {
76
+ if dbList.contains(fromFile) {
77
+ if String(file.suffix(3)) == ".db" {
78
+ toFile = file
79
+ .replacingOccurrences(of: ".db", with: "SQLite.db")
80
+ } else {
81
+ toFile = file + "SQLite.db"
82
+ }
83
+ try UtilsFile
84
+ .copyFromNames(dbPathURL: dbPathURL,
85
+ fromFile: fromFile,
86
+ databaseURL: databaseURL,
87
+ toFile: toFile)
88
+ }
89
+ } else {
68
90
  toFile = file
69
91
  .replacingOccurrences(of: ".db", with: "SQLite.db")
70
92
  try UtilsFile
@@ -98,9 +120,13 @@ class UtilsMigrate {
98
120
  throw UtilsMigrateError.addSQLiteSuffix(message: msg)
99
121
  }
100
122
  }
123
+ // swiftlint:enable cyclomatic_complexity
101
124
  // swiftlint:enable function_body_length
102
125
 
103
126
  // MARK: - deleteOldDatabase
127
+
128
+ // swiftlint:disable function_body_length
129
+ // swiftlint:disable cyclomatic_complexity
104
130
  class func deleteOldDatabases(folderPath: String, dbList: [String]) throws {
105
131
  do {
106
132
  let dbPathURL: URL = try UtilsMigrate
@@ -109,17 +135,35 @@ class UtilsMigrate {
109
135
  if FileManager.default.fileExists(atPath: dbPathURL.relativePath,
110
136
  isDirectory: &isDir) &&
111
137
  isDir.boolValue {
112
- let mDbList: [String] = try UtilsFile
113
- .getFileList(path: dbPathURL.relativePath, ext: ".db")
138
+ var mDbList: [String]
139
+ if dbList.count > 0 {
140
+ mDbList = try UtilsFile
141
+ .getFileList(path: dbPathURL.relativePath, ext: nil)
142
+ } else {
143
+ mDbList = try UtilsFile
144
+ .getFileList(path: dbPathURL.relativePath, ext: "db")
145
+ }
114
146
  for file: String in mDbList {
115
147
  if !file.contains("SQLite.db") {
116
- if dbList.contains(file) {
117
- let ret: Bool = try UtilsFile
118
- .deleteFile(dbPathURL: dbPathURL, fileName: file)
119
- if !ret {
120
- throw UtilsMigrateError
121
- .deleteOldDatabases(message: "deleteFileFailed")
148
+ if dbList.count > 0 {
149
+ if dbList.contains(file) {
150
+ let ret: Bool = try UtilsFile
151
+ .deleteFile(dbPathURL: dbPathURL, fileName: file)
152
+ if !ret {
153
+ throw UtilsMigrateError
154
+ .deleteOldDatabases(message: "deleteFileFailed")
155
+ }
156
+ }
157
+ } else {
158
+ if file.contains(".db") {
159
+ let ret: Bool = try UtilsFile
160
+ .deleteFile(dbPathURL: dbPathURL, fileName: file)
161
+ if !ret {
162
+ throw UtilsMigrateError
163
+ .deleteOldDatabases(message: "deleteFileFailed")
164
+ }
122
165
  }
166
+
123
167
  }
124
168
  }
125
169
  }
@@ -144,6 +188,8 @@ class UtilsMigrate {
144
188
  throw UtilsMigrateError.addSQLiteSuffix(message: msg)
145
189
  }
146
190
  }
191
+ // swiftlint:enable cyclomatic_complexity
192
+ // swiftlint:enable function_body_length
147
193
 
148
194
  // MARK: - getFolderURL
149
195
  class func getFolderURL(folderPath: String) throws -> URL {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/sqlite",
3
- "version": "3.3.1",
3
+ "version": "3.3.2",
4
4
  "description": "Community plugin for native & electron SQLite databases",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -55,10 +55,10 @@
55
55
  "prepublishOnly": "npm run build && npm run build-electron && npm run docgen"
56
56
  },
57
57
  "devDependencies": {
58
- "@capacitor/android": "^3.3.1",
59
- "@capacitor/core": "3.3.1",
58
+ "@capacitor/android": "^3.3.2",
59
+ "@capacitor/core": "3.3.2",
60
60
  "@capacitor/docgen": "^0.0.17",
61
- "@capacitor/ios": "^3.3.1",
61
+ "@capacitor/ios": "^3.3.2",
62
62
  "@ionic/eslint-config": "^0.3.0",
63
63
  "@ionic/prettier-config": "^1.0.1",
64
64
  "@ionic/swiftlint-config": "^1.1.2",
@@ -74,7 +74,7 @@
74
74
  "typescript": "~4.0.5"
75
75
  },
76
76
  "peerDependencies": {
77
- "@capacitor/core": "^3.3.1"
77
+ "@capacitor/core": "^3.3.2"
78
78
  },
79
79
  "prettier": "@ionic/prettier-config",
80
80
  "swiftlint": "@ionic/swiftlint-config",