Compare commits

...

1 Commits

27
otp.c
View File

@@ -3175,8 +3175,15 @@ void get_directory_display(const char* file_path, char* result, size_t result_si
if (path_after_media) { if (path_after_media) {
path_after_media++; // Skip the slash path_after_media++; // Skip the slash
// For /media/user/LABEL pattern, skip the username to get to the drive label
if (strstr(media_start, "/media/")) {
char* next_slash = strchr(path_after_media, '/');
if (next_slash) {
path_after_media = next_slash + 1;
}
}
// For /run/media/user/LABEL pattern, skip the username // For /run/media/user/LABEL pattern, skip the username
if (strstr(media_start, "/run/media/")) { else if (strstr(media_start, "/run/media/")) {
char* next_slash = strchr(path_after_media, '/'); char* next_slash = strchr(path_after_media, '/');
if (next_slash) { if (next_slash) {
path_after_media = next_slash + 1; path_after_media = next_slash + 1;
@@ -3185,15 +3192,23 @@ void get_directory_display(const char* file_path, char* result, size_t result_si
// Extract just the USB label (up to next slash or end) // Extract just the USB label (up to next slash or end)
char* label_end = strchr(path_after_media, '/'); char* label_end = strchr(path_after_media, '/');
char usb_label[32];
if (label_end) { if (label_end) {
size_t label_len = label_end - path_after_media; size_t label_len = label_end - path_after_media;
if (label_len > 11) label_len = 11; // Max 11 chars for display if (label_len > sizeof(usb_label) - 1) label_len = sizeof(usb_label) - 1;
strncpy(result, path_after_media, label_len); strncpy(usb_label, path_after_media, label_len);
result[label_len] = '\0'; usb_label[label_len] = '\0';
} else { } else {
// USB label is the last part // USB label is the last part
strncpy(result, path_after_media, result_size - 1); strncpy(usb_label, path_after_media, sizeof(usb_label) - 1);
result[result_size - 1] = '\0'; usb_label[sizeof(usb_label) - 1] = '\0';
}
// Format with USB: prefix, limiting total length to fit in result
snprintf(result, result_size, "USB:%s", usb_label);
// Truncate if too long
if (strlen(result) > 11) {
result[11] = '\0';
} }
return; return;
} }