Skip to content

TagSpaces is an offline, open source, document manager with tagging support

fix: indexing issues on read-only locations

Ilian Sapundshiev612ac28c3c96
diff --git a/src/renderer/hooks/LocationIndexContextProvider.tsx b/src/renderer/hooks/LocationIndexContextProvider.tsx
index e1699ae92..482234cf3 100644
--- a/src/renderer/hooks/LocationIndexContextProvider.tsx
+++ b/src/renderer/hooks/LocationIndexContextProvider.tsx
@@ -264,9 +264,6 @@ export const LocationIndexContextProvider = ({
): Promise<TS.FileSystemEntry[]> {
if (!index.current || index.current.length < 1 || indexExpired()) {
const location = findLocation(locationId);
- if (!location) {
- return index.current ?? [];
- }
const locationPath = await getLocationPath(location);
const directoryIndex = await loadIndexFromDisk(
locationPath,
@@ -278,11 +275,13 @@ export const LocationIndexContextProvider = ({
// and re-enhance the file from disk every time.
setIndex(directoryIndex);
return directoryIndex;
- } else if (!location.isReadOnly) {
+ } else if (!location?.isReadOnly) {
// Read-only locations have no way to produce or persist a fresh
// index, so falling through to createLocationIndex only risks
// returning an empty/failed walker result. Prefer returning
// index.current (likely undefined) and let the caller handle it.
+ // createLocationIndex itself handles an undefined location as a
+ // no-op, so optional chaining here preserves the original behavior.
await createLocationIndex(location);
}
}
@@ -1229,8 +1228,8 @@ export const LocationIndexContextProvider = ({
const indexAge = new Date().getTime() - indexFile.lmdt;
// Read-only locations can never refresh their on-disk index, so
// the disk copy is the best (and only) source — bypass the age
- // check, otherwise a stale tsi.json forces a walker fallback
- // that cannot persist and risks returning nothing.
+ // check. Otherwise a stale tsi.json forces a walker fallback
+ // that cannot persist and risks returning an empty/failed state.
if (
loc.isReadOnly ||
loc.disableIndexing ||
diff --git a/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx b/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx
index cfda1e645..7f10fde74 100644
--- a/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx
+++ b/src/renderer/hooks/PerspectiveSettingsContextProvider.tsx
@@ -196,6 +196,14 @@ export const PerspectiveSettingsContextProvider = ({
if (isDefaultSetting === undefined) {
isDefaultSetting = !haveLocalSetting();
}
+ // Read-only locations can't persist perspective settings — any write
+ // would surface as an "Error: read only Location" toast from
+ // saveFsEntryMeta's error handler. Keep the in-memory settings (already
+ // applied by setSettings) and skip the disk write.
+ const loc = findLocation();
+ if (loc?.isReadOnly) {
+ return;
+ }
const { settingsKey, ...cleanSettings } = settings.current;
if (Pro && !isDefaultSetting) {
setPerspectiveSettings(