okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
236cca71b
main
1/** 2* Where things live, and which system tool to call, per platform. 3* 4* The host used to assume POSIX in three places: it called /usr/bin/tar and /usr/bin/env, and it kept the tuning 5* and Time-skip state under $HOME/.local/state. On Windows those paths do not exist. State goes to 6* %LOCALAPPDATA%\Strata (the same place the Python side uses: strata_control/paths.py), and the system tools are 7* the ones Windows ships (System32\tar.exe, System32\where.exe). POSIX behavior is unchanged. 8* 9* Every function takes the environment and platform as arguments so tests can exercise both without a second OS. 10*/ 11import { homedir } from 'node:os' ; 12import { posix } from 'node:path' ; 13 14const winPath = ( ...parts ) => parts . join ( '\\' ); 15 16/** The folder under which Strata keeps per-user state (tuning jobs, Time-skip runs). */ 17export function stateRoot ( env = process . env , platform = process . platform , home = homedir ()) { 18if ( platform === 'win32' ) { 19const local = env . LOCALAPPDATA || winPath ( env . USERPROFILE || home , 'AppData' , 'Local' ); 20return winPath ( local , 'Strata' ); 21} 22return posix . join ( env . XDG_STATE_HOME || posix . join ( env . HOME || '.' , '.local' , 'state' ), 'strata' ); 23} 24 25const under = ( root , platform , name ) => ( platform === 'win32' ?winPath ( root , name ) :posix . join ( root , name )); 26 27export function tuningDir ( env = process . env , platform = process . platform , home = homedir ()) { 28return env . STRATA_TUNE_DIR || under ( stateRoot ( env , platform , home ), platform , 'tuning' ); 29} 30 31export function timeSkipDir ( env = process . env , platform = process . platform , home = homedir ()) { 32return env . STRATA_TIMESKIP_DIR || under ( stateRoot ( env , platform , home ), platform , 'time-skip' ); 33} 34 35function systemRoot ( env ) { 36return env . SystemRoot || env . SYSTEMROOT || env . windir || 'C:\\Windows' ; 37} 38 39/** The archive tool: Windows 10+ ships bsdtar as System32\tar.exe (it reads .zip and .tar.*); POSIX has /usr/bin/tar. */ 40export function tarBinary ( env = process . env , platform = process . platform ) { 41return platform === 'win32' ?winPath ( systemRoot ( env ), 'System32' , 'tar.exe' ) :'/usr/bin/tar' ; 42} 43 44/** The command that prints where a program is on PATH. */ 45export function whichCommand ( binary , env = process . env , platform = process . platform ) { 46if ( platform === 'win32' ) return { command :winPath ( systemRoot ( env ), 'System32' , 'where.exe' ), args :[ binary ] }; 47return { command :'/usr/bin/env' , args :[ 'which' , binary ] }; 48}