@samitouri / QOSami-HFS / commits / c8a38558

fix: uppercase version of DESCRIPT.ION was not supported on linux #1176

Massimo Melina committed Mar 3, 2026 at 00:17 UTC c8a38558a47c7271fad7e8e586d088948b380804
1 file changed +12 -5
src/comments.ts
+12 -5
@@ -1,13 +1,14 @@
1 import { defineConfig } from './config'
2 import { dirname, basename, join } from 'path'
3 import { CFG } from './cross'
4 -import { parseFile, parseFileCache, createSafeWriteStream } from './util-files'
4 +import { parseFile, parseFileCache, createSafeWriteStream, exists } from './util-files'
5 import { loadFileAttr, singleWorkerFromBatchWorker, storeFileAttr } from './misc'
6 import _ from 'lodash'
7 import iconv from 'iconv-lite'
8 import { unlink } from 'node:fs/promises'
9
10 export const DESCRIPT_ION = 'descript.ion'
11 +const DESCRIPT_ION_ALT = 'DESCRIPT.ION'
12 const commentsStorage = defineConfig<'' | 'attr' | 'attr+ion'>(CFG.comments_storage, '',
13 v => ['', 'attr+ion'].includes(v)) // compiled tell us if we are using descript.ion
14 defineConfig('descript_ion', true, (v, more) => { // legacy: convert previous setting
@@ -52,7 +53,7 @@ const setCommentDescriptIon = singleWorkerFromBatchWorker(async (jobs: [path: st
53 else
54 comments.set(file, comment)
55 }
55 - const path = join(folder, DESCRIPT_ION)
56 + const path = await filePathHelper(folder)
57 if (!comments.size)
58 return unlink(path)
59 // encode comments in descript.ion format
@@ -74,10 +75,16 @@ export function areCommentsEnabled() {
75 return true // true since we introduced comments in file-attr
76 }
77
78 +async function filePathHelper(folder: string) {
79 + const main = join(folder, DESCRIPT_ION)
80 + const alt = join(folder, DESCRIPT_ION_ALT)
81 + return await exists(alt) && !await exists(main) ? alt : main
82 +}
83 +
84 const MULTILINE_SUFFIX = Buffer.from([4, 0xC2])
78 -function readDescriptIon(path: string) {
85 +async function readDescriptIon(path: string) {
86 // decoding could also be done with native TextDecoder.decode, but we need iconv for the encoding anyway
80 - return parseFile(join(path, DESCRIPT_ION), raw => {
87 + return parseFile(await filePathHelper(path), raw => {
88 // for simplicity we "remove" the sequence MULTILINE_SUFFIX before iconv.decode messes it up
89 for (let i=0; i<raw.length; i++)
90 if (raw[i] === MULTILINE_SUFFIX[0] && raw[i+1] === MULTILINE_SUFFIX[1] && [undefined,13,10].includes(raw[i+2]))
@@ -97,6 +104,6 @@ function readDescriptIon(path: string) {
104
105 descriptIonEncoding.sub(() => { // invalidate cache at encoding change
106 for (const k of parseFileCache.keys())
100 - if (k.endsWith(DESCRIPT_ION))
107 + if (k.endsWith(DESCRIPT_ION) || k.endsWith(DESCRIPT_ION_ALT))
108 parseFileCache.delete(k)
109 })
\ No newline at end of file