summarylogtreecommitdiffstats
path: root/file-name-length-limit.patch
blob: 580a388c96493fad9e2ea3a9a6143982b853685e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
--- a/infinitychan.py
+++ b/infinitychan.py
@@ -301,11 +301,18 @@
                 else:
                     name = file['tim']
                 if mode == 'unix_original':
-                    name += '_' + file['filename']
+                    if len(''.join([name, '_', file['filename'],
+                                    file['ext']]).encode('utf-8')) \
+                       <= os.statvfs(os.getcwd()).f_namemax:
+                        name += '_' + file['filename']
             elif mode == 'plain':
                 name = file['tim']
             elif mode == 'original':
-                name = file['filename']
+                if len((file['filename'] + file['ext']).encode('utf-8')) \
+                   <= os.statvfs(os.getcwd()).f_namemax:
+                    name = file['filename']
+                else:
+                    name = file['tim']
             else:
                 raise RuntimeError("Unknown mode {}".format(mode))
             name += file['ext']