Skip to content

Commit 323b5aa

Browse files
authored
Use XDG_STATE_HOME for logfiles instead of ~/.cinnamon (#11186)
* Use `XDG_STATE_HOME` for logfiles instead of `~/.cinnamon` Although I've not seen any of these logfiles on my system. glass.log entry was removed because it doesn't exists anymore. * Add try/except around `get_user_state_dir` for backwards compatibility
1 parent 844493a commit 323b5aa

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

files/usr/bin/cinnamon-launcher

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import psutil
1212
import threading
1313
import gi
1414
gi.require_version('Gtk', '3.0') # noqa
15-
from gi.repository import Gtk, GLib, Gio
15+
from gi.repository import Gtk, GLib, Gio, GLib
1616

1717
FALLBACK_COMMAND = "metacity"
1818
FALLBACK_ARGS = ("--replace",)
@@ -113,7 +113,11 @@ class Launcher():
113113
os.execvp(sys.argv[0], sys.argv)
114114

115115
def log_kill(self, memory, limit, delay):
116-
directory = os.path.expanduser("~/.cinnamon")
116+
try:
117+
directory = os.path.join(GLib.get_user_state_dir(), 'cinnamon')
118+
except AttributeError:
119+
directory = os.path.expanduser("~/.cinnamon")
120+
117121
string = "%s - Usage: %d MB - Limit: %d MB - Freq: %s sec" % (time.strftime("%Y.%m.%d %H:%M:%S"), memory, limit, delay)
118122
if not os.path.exists(directory):
119123
os.mkdir(directory)

files/usr/share/cinnamon/cinnamon-looking-glass/cinnamon-looking-glass.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ def __init__(self, parent):
146146
box.add(label)
147147

148148
self.store = Gtk.ListStore(str, str)
149-
self.store.append(["glass.log", "~/.cinnamon/glass.log"])
150149
self.store.append(["custom", "<Select file>"])
151150

152151
self.combo = Gtk.ComboBox.new_with_model(self.store)

python3/cinnamon/logger.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
import os
44
import threading
55
import queue
6+
from pathlib import Path
7+
from gi.repository import GLib
68

79
# Share among multiple Harvesters
8-
logfile = '%s/.cinnamon/harvester.log' % os.path.expanduser("~")
10+
try:
11+
logfile = os.path.join(GLib.get_user_state_dir(), 'cinnamon', 'harvester.log')
12+
except AttributeError:
13+
logfile = '%s/.cinnamon/harvester.log' % os.path.expanduser("~")
914

1015
class ActivityLogger():
1116
def __init__(self):
@@ -17,6 +22,9 @@ def log(self, entry):
1722
self.queue.put(entry)
1823

1924
def write_to_file_thread(self):
25+
directory = Path(logfile).parent
26+
if not directory.exists():
27+
os.makedirs(directory)
2028
while True:
2129
entry = self.queue.get()
2230
with open(logfile, "a") as f:

0 commit comments

Comments
 (0)