Adapt path where log files are stored
Split up the directory named after the device UUID into subdirectories
to decrease the number of directories in the first level.
Issue: HIC-237
Change-Id: Ifc33728553e515f6efeb2e12ad11c7e2d6eaf181
diff --git a/crashreports/models.py b/crashreports/models.py
index fce6976..318ddac 100644
--- a/crashreports/models.py
+++ b/crashreports/models.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""Models for devices, heartbeats, crashreports and log files."""
+import os
import uuid
from django.db import models, transaction
@@ -58,6 +59,10 @@
def crashreport_file_name(instance, filename):
"""Generate the full path for new uploaded log files.
+ The path is created by splitting up the device UUID into 3 parts: The
+ first 2 characters, the second 2 characters and the rest. This way the
+ number of directories in each subdirectory does not get too big.
+
Args:
instance: The log file instance.
filename: The name of the actual log file.
@@ -65,14 +70,13 @@
Returns: The generated path including the file name.
"""
- return "/".join(
- [
- "crashreport_uploads",
- instance.crashreport.device.uuid,
- str(instance.crashreport.id),
- str(instance.crashreport.date),
- filename,
- ]
+ return os.path.join(
+ "crashreport_uploads",
+ str(instance.crashreport.device.uuid)[0:2],
+ str(instance.crashreport.device.uuid)[2:4],
+ str(instance.crashreport.device.uuid)[4:],
+ str(instance.crashreport.id),
+ filename,
)