fix: ensure we don't try to remove unindexed undefined symlinks
This commit is contained in:
parent
d4c862824d
commit
54d284e597
3 changed files with 44 additions and 40 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@andyburke/fsdb",
|
"name": "@andyburke/fsdb",
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./fsdb.ts",
|
".": "./fsdb.ts",
|
||||||
|
|
|
||||||
78
fsdb.ts
78
fsdb.ts
|
|
@ -7,51 +7,51 @@
|
||||||
* import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers';
|
* import { FSDB_INDEXER_SYMLINKS } from '@andyburke/fsdb/indexers';
|
||||||
* import { by_character, by_email, by_phone } from '@andyburke/fsdb/organizers';
|
* import { by_character, by_email, by_phone } from '@andyburke/fsdb/organizers';
|
||||||
*
|
*
|
||||||
* type ITEM = {
|
* type ITEM = {
|
||||||
* id: string;
|
* id: string;
|
||||||
* email: string;
|
* email: string;
|
||||||
* phone: string;
|
* phone: string;
|
||||||
* value: string;
|
* value: string;
|
||||||
* };
|
* };
|
||||||
*
|
*
|
||||||
* const item_collection: fsdb.FSDB_COLLECTION<ITEM> = new fsdb.FSDB_COLLECTION<ITEM>({
|
* const item_collection: fsdb.FSDB_COLLECTION<ITEM> = new fsdb.FSDB_COLLECTION<ITEM>({
|
||||||
* name: 'test-03-items',
|
* name: 'test-03-items',
|
||||||
* root: get_data_dir() + '/test-03-items',
|
* root: get_data_dir() + '/test-03-items',
|
||||||
* indexers: {
|
* indexers: {
|
||||||
* email: new FSDB_INDEXER_SYMLINKS<ITEM>({
|
* email: new FSDB_INDEXER_SYMLINKS<ITEM>({
|
||||||
* name: 'email',
|
* name: 'email',
|
||||||
* field: 'email',
|
* field: 'email',
|
||||||
* organize: by_email
|
* organize: by_email
|
||||||
* }),
|
* }),
|
||||||
* phone: new FSDB_INDEXER_SYMLINKS<ITEM>({
|
* phone: new FSDB_INDEXER_SYMLINKS<ITEM>({
|
||||||
* name: 'phone',
|
* name: 'phone',
|
||||||
* field: 'phone',
|
* field: 'phone',
|
||||||
* organize: by_phone
|
* organize: by_phone
|
||||||
* }),
|
* }),
|
||||||
* value: new FSDB_INDEXER_SYMLINKS<ITEM>({
|
* value: new FSDB_INDEXER_SYMLINKS<ITEM>({
|
||||||
* name: 'value',
|
* name: 'value',
|
||||||
* organize: by_character,
|
* organize: by_character,
|
||||||
* get_values_to_index: (item: ITEM) => item.value.split(/\W/).filter((word) => word.length > 3),
|
* get_values_to_index: (item: ITEM) => item.value.split(/\W/).filter((word) => word.length > 3),
|
||||||
* to_many: true
|
* to_many: true
|
||||||
* })
|
* })
|
||||||
* }
|
* }
|
||||||
* });
|
* });
|
||||||
*
|
*
|
||||||
* const item = {
|
* const item = {
|
||||||
* id: lurid(),
|
* id: lurid(),
|
||||||
* email: random_email_address(),
|
* email: random_email_address(),
|
||||||
* phone: random_phone_number(),
|
* phone: random_phone_number(),
|
||||||
* value: random_sentence()
|
* value: random_sentence()
|
||||||
* };
|
* };
|
||||||
*
|
*
|
||||||
* const stored_item: ITEM = await item_collection.create(item);
|
* const stored_item: ITEM = await item_collection.create(item);
|
||||||
* const fetched_by_email: ITEM = (await item_collection.find({ email: item.email })).map((entry) => entry.load()).shift();
|
* const fetched_by_email: ITEM = (await item_collection.find({ email: item.email })).map((entry) => entry.load()).shift();
|
||||||
* const fetched_by_phone: ITEM = (await item_collection.find({ phone: item.phone })).map((entry) => entry.load()).shift();
|
* const fetched_by_phone: ITEM = (await item_collection.find({ phone: item.phone })).map((entry) => entry.load()).shift();
|
||||||
* const fetched_by_word_in_value: ITEM = (await item_collection.find({ value: word })).map((entry) => entry.load()).shift();
|
* const fetched_by_word_in_value: ITEM = (await item_collection.find({ value: word })).map((entry) => entry.load()).shift();
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* @module
|
* @module
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as fs from '@std/fs';
|
import * as fs from '@std/fs';
|
||||||
import * as path from '@std/path';
|
import * as path from '@std/path';
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,10 @@ export class FSDB_INDEXER_SYMLINKS<T> implements FSDB_INDEXER<T> {
|
||||||
const item_dir: string = path.dirname(item_path);
|
const item_dir: string = path.dirname(item_path);
|
||||||
|
|
||||||
for (const value of values) {
|
for (const value of values) {
|
||||||
|
if (typeof value === 'undefined') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
const item_dir_reverse_link: string = path.join(item_dir, `.index.symlink.${this.config.name}.${sanitize(value)}`);
|
const item_dir_reverse_link: string = path.join(item_dir, `.index.symlink.${this.config.name}.${sanitize(value)}`);
|
||||||
if (!fs.existsSync(item_dir_reverse_link)) {
|
if (!fs.existsSync(item_dir_reverse_link)) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue