Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function _deleteConfiguration(): Promise < void > {
try {
const configVersions : Array < Object > = await Database.getConfigVersions();
const clearVersions: Array < Object > = [];
if (configVersions == null) {
return;
}
for (let i = 0; i < configVersions.length; i++) {
try {
const dir = CONFIG_SUBDIRECTORIES[configVersions[i].type];
await RNFS.unlink(CONFIG_DIRECTORY + dir + configVersions[i].name);
} catch (e) {
// do nothing - file doesn't exist
}
clearVersions.push({
name: configVersions[i].name,
type: configVersions[i].type,
version: 0,
});
}
await Database.updateConfigVersions(clearVersions);
await RNFS.unlink(CONFIG_DIRECTORY);
} catch (err) {
console.log('Error accessing database while clearing versions.', err);
}
}
await RNFS.moveFile(
TEMP_CONFIG_DIRECTORY + configurationUpdates[i].name,
CONFIG_DIRECTORY + CONFIG_SUBDIRECTORIES[configurationUpdates[i].type] + configurationUpdates[i].name
);
configRowUpdates.push({
name: configurationUpdates[i].name,
type: configurationUpdates[i].type,
version: configurationUpdates[i].newVersion,
});
}
// Delete temporary downloads
await RNFS.unlink(TEMP_CONFIG_DIRECTORY);
// Update config versions in database
await Database.updateConfigVersions(configRowUpdates);
university = null;
await module.exports.init();
} catch (e) {
throw e;
}
}
if (!__DEV__) {
return;
}
try {
const configVersions = await Database.getConfigVersions();
const clearVersions: ConfigFile[] = [];
if (configVersions == undefined) {
return;
}
for (const configVersion of configVersions) {
try {
const dir = CONFIG_SUBDIRECTORIES[configVersion.type];
await RNFS.unlink(CONFIG_DIRECTORY + dir + configVersion.name);
} catch (e) {
// do nothing - file doesn't exist
}
clearVersions.push({
name: configVersion.name,
size: 0,
type: configVersion.type,
url: '',
version: 0,
});
}
await Database.updateConfigVersions(clearVersions);
const exists = await RNFS.exists(CONFIG_DIRECTORY);
.done(async() => {
try {
console.log(`Finished downloading: ${task.id}, deleting it...`);
await RNFS.unlink(filePath);
console.log(`Deleted ${task.id}`);
} catch (e) {
console.error(e);
}
delete this.idsToData[task.id];
this.saveDownloads();
this.setState(produce(draft => {
delete draft.downloadsData[task.id];
draft.downloads.splice(draft.downloads.indexOf(task.id), 1);
}));
})
.error(err => {
}
clearVersions.push({
name: configVersion.name,
size: 0,
type: configVersion.type,
url: '',
version: 0,
});
}
await Database.updateConfigVersions(clearVersions);
const exists = await RNFS.exists(CONFIG_DIRECTORY);
if (exists) {
await RNFS.unlink(CONFIG_DIRECTORY);
}
} catch (err) {
console.error('Error accessing database while clearing versions.', err);
}
}
componentWillMount() {
RNFS.unlink(RNFS.DocumentDirectoryPath + "/nkjv.realm");
RNFS.unlink(RNFS.DocumentDirectoryPath + "/nkjv.realm.lock");
if (Platform.OS == "android") {
RNFS.copyFileAssets("nkjv.realm", RNFS.DocumentDirectoryPath + "/nkjv.realm");
RNFS.copyFileAssets("nkjv.realm.lock", RNFS.DocumentDirectoryPath + "/nkjv.realm.lock");
} else {
try {
RNFS.copyFile(RNFS.MainBundlePath + "/nkjv.realm", RNFS.DocumentDirectoryPath + "/nkjv.realm");
RNFS.copyFile(RNFS.MainBundlePath + "/nkjv.realm.lock", RNFS.DocumentDirectoryPath + "/nkjv.realm.lock");
} catch (e) {
console.log("FILE ALREADY EXISTS");
}
}
}
_onShowSearch() {
async function deleteFileIfExists(path: string) {
try {
const gethLockFileExists = await RNFS.exists(path)
if (gethLockFileExists) {
Logger.debug('Geth@deleteFileIfExists', `Dir ${path} exists. Attempting to delete`)
await RNFS.unlink(path)
return true
} else {
Logger.debug('Geth@deleteFileIfExists', `Dir ${path} does not exist`)
return true
}
} catch (error) {
Logger.error('Geth@deleteFileIfExists', `Failed to delete ${path}`, error)
return false
}
}
.then((res) => {
if (res) {
RNFS
.unlink(filePath)
.catch((err) => {});
}
});
}
async delete(key) {
const file = await this._getFileForKey(key);
if (file) {
return RNFS.unlink(`${this._mapDir}/${file}`);
}
return Promise.resolve();
}