Skip to content

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

fix: handling the case of indexing of a read-only location

Ilian Sapundshiev0877cb952891
diff --git a/CLAUDE.md b/CLAUDE.md
index a755840b8..79c3e9bb6 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -159,6 +159,15 @@ The app runs on multiple platforms and storage backends. When working with file/
When comparing paths (e.g., `startsWith`, equality checks), normalize **both** sides with the same functions. A common bug pattern: applying `cleanFrontDirSeparator` (strips leading `/`) to one path but not the other, breaking the comparison on Mac/Linux where absolute paths start with `/`. Path utilities live in `@tagspaces/tagspaces-common/paths.js`.
+## Read-only Locations
+
+`CommonLocation.isReadOnly` gates all writes: index/fulltext files, sidecar meta, thumbnails, tag-in-filename renames, `.ts/tsm.json`. Write primitives (`saveTextFilePromise`, `saveBinaryFilePromise`, `renameFilePromise`) reject with `Error('read only Location')`, but callers often swallow that into a sentinel (`false` / `undefined` / `[]`).
+
+- **Classic bug**: caller does `setState(result)` without checking — the sentinel wipes previously good state. Null-check before assigning into shared refs (`index.current`, etc.); prefer `Array.isArray(x) && x.length > 0`.
+- **In-memory work is fine; serialization isn't**: follow the `createNotWorkerIndex` split — compute the fresh index, but wrap the persist call in `if (!loc.isReadOnly)`.
+- **Short-circuit automatic writes** when readonly + usable data already exists (see `searchLocationIndex` in `LocationIndexContextProvider.tsx`).
+- **Disable user-triggered write buttons** with `disabled={currentLocation?.isReadOnly}` and swap the tooltip to `t('core:readOnlyLocationIndexDisabled')`. Silent no-op on click is bad UX. Pattern: FolderViz/Calendar `MainToolbar.tsx`.
+
## Translations / i18n
- English source: `src/renderer/locales/en/core.json`
diff --git a/src/renderer/components/HowToStart.tsx b/src/renderer/components/HowToStart.tsx
index 4e8d2ec68..3636d2963 100644
--- a/src/renderer/components/HowToStart.tsx
+++ b/src/renderer/components/HowToStart.tsx
@@ -317,7 +317,7 @@ function HowToStart() {
>
{index === steps.length - 1
? t('core:finish')
- : t('core:goforward')}
+ : t('core:next')}
</TsButton>
</div>
</Box>
diff --git a/src/renderer/hooks/LocationIndexContextProvider.tsx b/src/renderer/hooks/LocationIndexContextProvider.tsx
index ee3d153a8..508ddf218 100644
--- a/src/renderer/hooks/LocationIndexContextProvider.tsx
+++ b/src/renderer/hooks/LocationIndexContextProvider.tsx
@@ -629,8 +629,14 @@ export const LocationIndexContextProvider = ({
extractLinks,
)
.then((directoryIndex) => {
- if (isCurrentLocation) {
- // Load index only if current location
+ // createDirectoryIndexWrapper returns `false` on error — guard
+ // against that sentinel wiping a previously good index (see
+ // readonly-location / slow-S3 failure paths).
+ if (
+ isCurrentLocation &&
+ Array.isArray(directoryIndex) &&
+ directoryIndex.length > 0
+ ) {
setIndex(directoryIndex);
}
isIndexing.current = undefined;
@@ -897,12 +903,21 @@ export const LocationIndexContextProvider = ({
? currentTime - indexLoadedOn.current
: 0;
+ // On readonly locations a usable existing index (in memory or on
+ // disk) is reused as-is — we cannot persist a fresh one anyway, and
+ // a walker error would wipe the good index via the `false` sentinel
+ // from createDirectoryIndexWrapper.
+ const hasUsableIndex = index.current && index.current.length > 0;
+ const skipReindexOnReadOnly =
+ currentLocation.isReadOnly && hasUsableIndex;
+
if (
- searchQuery.forceIndexing ||
- (!currentLocation.disableIndexing &&
- (!index.current ||
- index.current.length < 1 ||
- indexAge > maxIndexAge.current))
+ !skipReindexOnReadOnly &&
+ (searchQuery.forceIndexing ||
+ (!currentLocation.disableIndexing &&
+ (!index.current ||
+ index.current.length < 1 ||
+ indexAge > maxIndexAge.current)))
) {
console.log('Start creating index for : ' + currentPath);
const newIndex = await createDirectoryIndexWrapper(
@@ -917,7 +932,9 @@ export const LocationIndexContextProvider = ({
undefined,
!!searchQuery.forceIndexing,
);
- setIndex(newIndex);
+ if (Array.isArray(newIndex) && newIndex.length > 0) {
+ setIndex(newIndex);
+ }
}
getSearchResults(index.current, searchQuery).then((results) => {
setSearchResults(results);
diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.json
index 5495cb05d..7af1adf77 100644
--- a/src/renderer/locales/en/core.json
+++ b/src/renderer/locales/en/core.json
@@ -404,6 +404,7 @@
"sort": "Sort",
"thirdPartyLibs": "Third Party Libraries",
"indexLocation": "Refresh Location Index",
+ "readOnlyLocationIndexDisabled": "Location is read-only — index cannot be refreshed",
"linksGraphIndexConfirm": "The Links Graph requires full-text indexing with link extraction enabled. This process may take a while depending on the number and size of the files in the location. Do you want to proceed?",
"forceReindexing": "Force reindexing",
"indexEmpty": "index is empty",