@@ -48,28 +48,6 @@ QString QsPaths::ipcPath(const QString& id) {
4848 return QDir (QsPaths::basePath (id)).filePath (" ipc.sock" );
4949}
5050
51- QDir* QsPaths::cacheDir () {
52- if (this ->cacheState == DirState::Unknown) {
53- auto dir = QDir (QStandardPaths::writableLocation (QStandardPaths::CacheLocation));
54- dir = QDir (dir.filePath (" by-shell" ));
55- dir = QDir (dir.filePath (this ->shellId ));
56- this ->mCacheDir = dir;
57-
58- qCDebug (logPaths) << " Initialized cache path:" << dir.path ();
59-
60- if (!dir.mkpath (" ." )) {
61- qCCritical (logPaths) << " Could not create cache directory at" << dir.path ();
62-
63- this ->cacheState = DirState::Failed;
64- } else {
65- this ->cacheState = DirState::Ready;
66- }
67- }
68-
69- if (this ->cacheState == DirState::Failed) return nullptr ;
70- else return &this ->mCacheDir ;
71- }
72-
7351QDir* QsPaths::baseRunDir () {
7452 if (this ->baseRunState == DirState::Unknown) {
7553 auto runtimeDir = qEnvironmentVariable (" XDG_RUNTIME_DIR" );
@@ -230,6 +208,72 @@ void QsPaths::linkPathDir() {
230208 }
231209}
232210
211+ QDir QsPaths::shellDataDir () {
212+ if (this ->shellDataState == DirState::Unknown) {
213+ auto dir = QDir (QStandardPaths::writableLocation (QStandardPaths::AppDataLocation));
214+ dir = QDir (dir.filePath (" by-shell" ));
215+ dir = QDir (dir.filePath (this ->shellId ));
216+ this ->mShellDataDir = dir;
217+
218+ qCDebug (logPaths) << " Initialized data path:" << dir.path ();
219+
220+ if (!dir.mkpath (" ." )) {
221+ qCCritical (logPaths) << " Could not create data directory at" << dir.path ();
222+
223+ this ->shellDataState = DirState::Failed;
224+ } else {
225+ this ->shellDataState = DirState::Ready;
226+ }
227+ }
228+
229+ // Returning no path on fail might result in files being written in unintended locations.
230+ return this ->mShellDataDir ;
231+ }
232+
233+ QDir QsPaths::shellStateDir () {
234+ if (this ->shellStateState == DirState::Unknown) {
235+ auto dir = QDir (QStandardPaths::writableLocation (QStandardPaths::StateLocation));
236+ dir = QDir (dir.filePath (" by-shell" ));
237+ dir = QDir (dir.filePath (this ->shellId ));
238+ this ->mShellStateDir = dir;
239+
240+ qCDebug (logPaths) << " Initialized state path:" << dir.path ();
241+
242+ if (!dir.mkpath (" ." )) {
243+ qCCritical (logPaths) << " Could not create state directory at" << dir.path ();
244+
245+ this ->shellStateState = DirState::Failed;
246+ } else {
247+ this ->shellStateState = DirState::Ready;
248+ }
249+ }
250+
251+ // Returning no path on fail might result in files being written in unintended locations.
252+ return this ->mShellStateDir ;
253+ }
254+
255+ QDir QsPaths::shellCacheDir () {
256+ if (this ->shellCacheState == DirState::Unknown) {
257+ auto dir = QDir (QStandardPaths::writableLocation (QStandardPaths::CacheLocation));
258+ dir = QDir (dir.filePath (" by-shell" ));
259+ dir = QDir (dir.filePath (this ->shellId ));
260+ this ->mShellCacheDir = dir;
261+
262+ qCDebug (logPaths) << " Initialized cache path:" << dir.path ();
263+
264+ if (!dir.mkpath (" ." )) {
265+ qCCritical (logPaths) << " Could not create cache directory at" << dir.path ();
266+
267+ this ->shellCacheState = DirState::Failed;
268+ } else {
269+ this ->shellCacheState = DirState::Ready;
270+ }
271+ }
272+
273+ // Returning no path on fail might result in files being written in unintended locations.
274+ return this ->mShellCacheDir ;
275+ }
276+
233277void QsPaths::createLock () {
234278 if (auto * runDir = this ->instanceRunDir ()) {
235279 auto path = runDir->filePath (" instance.lock" );
0 commit comments