Skip to content

Commit de0a49b

Browse files
committed
catch missing xattr fields
1 parent 3be4205 commit de0a49b

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/frontend/stores/FileStore.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,30 @@ class FileStore {
148148
const absolutePath = file.absolutePath;
149149

150150
try {
151-
// a buffer with comma separated strings
152-
const kdeTags = await getAttribute(absolutePath, 'user.xdg.tags')
153-
// balooScore is 5/5 stars, but is double in xfattr
154-
const balooScore = await getAttribute(absolutePath, 'user.baloo.rating')
151+
// any of these fields may, or may not be present
152+
let kdeTags = Buffer.from('')
153+
let balooScore = Buffer.from('')
154+
try {
155+
// a buffer with comma separated strings
156+
kdeTags = await getAttribute(absolutePath, 'user.xdg.tags')
157+
} catch (e) {
158+
console.error('Error reading user.xdg.tags for', absolutePath, e);
159+
}
160+
try {
161+
// balooScore is 5/5 stars, but is double in xfattr
162+
balooScore = await getAttribute(absolutePath, 'user.baloo.rating')
163+
} catch (e) {
164+
console.error('Error reading user.baloo.rating for', absolutePath, e);
165+
}
166+
155167
// convert buffer to string, then split in array. Also remove trailing whitespace
156168
let tagsNameHierarchies = kdeTags.toString().split(',').filter(String)
157-
tagsNameHierarchies.push('score:' + balooScore)
169+
// if there is no score, skip adding a tag for it
170+
if (balooScore.toString() != '') {
171+
tagsNameHierarchies.push('score:' + balooScore.toString())
172+
}
158173

159174
// Now that we know the tag names in file metadata, add them to the files in OneFolder
160-
161175
const { tagStore } = this.rootStore;
162176
for (const tagHierarchy of tagsNameHierarchies) {
163177
const match = tagStore.findByName(tagHierarchy[tagHierarchy.length - 1]);

0 commit comments

Comments
 (0)