Skip to content

Commit 598aec5

Browse files
committed
feat: add support for Linux directory paths and storage analysis
- Add default JetBrains and Google paths for Linux and macOS - Update storage analysis logic to handle Linux-specific directory structures - Implement conditional path resolution for logs and caches on Linux - Refactor scanning logic to distinguish between operating systems during analysis
1 parent 9e159b3 commit 598aec5

2 files changed

Lines changed: 52 additions & 14 deletions

File tree

composeApp/src/jvmMain/kotlin/com/meet/dev/analyzer/core/utility/DefaultPath.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,17 @@ fun getDefaultJetbrainsFolderPaths(): List<String> {
4747
"$userHome\\AppData\\Local\\JetBrains",
4848
"$userHome\\AppData\\Roaming\\JetBrains"
4949
)
50-
51-
else -> listOf(
50+
os.contains("mac") -> listOf(
5251
"$userHome/Library/Caches/JetBrains",
5352
"$userHome/Library/Logs/JetBrains",
5453
"$userHome/Library/Application Support/JetBrains"
5554
)
55+
56+
else -> listOf( // Linux / Unix
57+
"$userHome/.cache/JetBrains",
58+
"$userHome/.cache/JetBrains",
59+
"$userHome/.config/JetBrains"
60+
)
5661
}
5762
}
5863

@@ -66,11 +71,17 @@ fun getDefaultGoogleFolderPaths(): List<String> {
6671
"$userHome\\AppData\\Roaming\\Google"
6772
)
6873

69-
else -> listOf(
74+
os.contains("mac") -> listOf(
7075
"$userHome/Library/Caches/Google",
7176
"$userHome/Library/Logs/Google",
7277
"$userHome/Library/Application Support/Google"
7378
)
79+
80+
else -> listOf( // Linux / Unix
81+
"$userHome/.cache/Google",
82+
"$userHome/.cache/Google",
83+
"$userHome/.config/Google"
84+
)
7485
}
7586
}
7687

composeApp/src/jvmMain/kotlin/com/meet/dev/analyzer/data/repository/storage/StorageAnalyzerRepositoryImpl.kt

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,45 @@ class StorageAnalyzerRepositoryImpl(
7676
fun scanBase(
7777
vendor: String,
7878
category: String,
79-
basePath: String
79+
basePath: String,
80+
isLinux: Boolean
8081
): List<IdeInstallation> {
8182
val dir = File(basePath)
8283
return dir.listFiles()
8384
?.filter { it.isDirectory && it.name.any { ch -> ch.isDigit() } }
84-
?.mapNotNull { file ->
85-
val sizeBytes = Utils.calculateFolderSize(file)
86-
val sizeReadable = Utils.formatSize(sizeBytes)
87-
val info = extractIdeNameAndVersionByFirstDigit(file.name)
88-
val (ideName, version) = info
85+
?.mapNotNull { ideDir ->
86+
val targetDir = when {
87+
isLinux && category == "LOGS" ->
88+
File(ideDir, "log")
8989

90+
else ->
91+
ideDir
92+
}
93+
94+
if (!targetDir.exists()) return@mapNotNull null
95+
96+
val sizeBytes = when {
97+
isLinux && category == "CACHES" ->
98+
ideDir.listFiles()
99+
?.filter { it.name != "log" }
100+
?.sumOf { Utils.calculateFolderSize(it) }
101+
?: 0L
102+
103+
else ->
104+
Utils.calculateFolderSize(targetDir)
105+
}
106+
107+
val (ideName, version) =
108+
extractIdeNameAndVersionByFirstDigit(ideDir.name)
90109
IdeInstallation(
91-
name = file.name,
110+
name = ideDir.name,
92111
ideName = ideName,
93112
version = version,
94113
category = category,
95-
path = file.absolutePath,
114+
path = targetDir.absolutePath,
96115
sizeBytes = sizeBytes,
97-
vendor = vendor,
98-
sizeReadable = sizeReadable
116+
sizeReadable = Utils.formatSize(sizeBytes),
117+
vendor = vendor
99118
)
100119
} ?: emptyList()
101120
}
@@ -140,12 +159,20 @@ class StorageAnalyzerRepositoryImpl(
140159
try {
141160
val os = System.getProperty("os.name").lowercase()
142161
val isWindows = os.contains("windows")
162+
val isLinux = !os.contains("windows") && !os.contains("mac")
143163
val basePaths = buildBasePaths(isWindows = isWindows)
144164

145165
val allInstallations = buildList {
146166
basePaths.forEach { (vendor, categories) ->
147167
categories.forEach { (category, path) ->
148-
addAll(scanBase(vendor, category, path))
168+
addAll(
169+
scanBase(
170+
vendor = vendor,
171+
category = category,
172+
basePath = path,
173+
isLinux = isLinux
174+
)
175+
)
149176
}
150177
}
151178
}

0 commit comments

Comments
 (0)