summaryrefslogtreecommitdiff
path: root/scripts/sync-to-project.ps1
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/sync-to-project.ps1')
-rw-r--r--scripts/sync-to-project.ps162
1 files changed, 37 insertions, 25 deletions
diff --git a/scripts/sync-to-project.ps1 b/scripts/sync-to-project.ps1
index 5c3fd9c..aef1249 100644
--- a/scripts/sync-to-project.ps1
+++ b/scripts/sync-to-project.ps1
@@ -90,24 +90,30 @@ function Get-ProjectPath {
[string]$originalPath
)
- # Nettoyer le chemin original pour créer un nom de fichier sûr
- $safeName = $originalPath -replace '[\\/:*?"<>|]', '_'
- $safeName = $safeName -replace '^%', '' -replace '%$', ''
- $safeName = $safeName -replace '^~', 'home'
+ # Nettoyer chaque partie du chemin
+ $parts = $originalPath -split '[\\/]'
+ $safeParts = @()
- # Si le chemin contient des séparateurs, préserver la structure
- if ($originalPath -match '[\\/]') {
- $parts = $originalPath -split '[\\/]'
- $fileName = $parts[-1]
- $parentDirs = $parts[0..($parts.Length - 2)] -join '_'
- if ($parentDirs) {
- $safeName = "${parentDirs}_${fileName}"
- } else {
- $safeName = $fileName
+ foreach ($part in $parts) {
+ # Nettoyer chaque partie : remplacer les caractères invalides et les variables
+ $safePart = $part -replace '[\\/:*?"<>|]', '_'
+ $safePart = $safePart -replace '^%', 'var_' -replace '%$', '' -replace '%', '_'
+ $safePart = $safePart -replace '^~', 'home'
+
+ # Si la partie est vide après nettoyage, utiliser un nom par défaut
+ if ([string]::IsNullOrWhiteSpace($safePart)) {
+ $safePart = "root"
}
+
+ $safeParts += $safePart
}
- return Join-Path "configs" $system $safeName
+ # Rejoindre toutes les parties avec des underscores
+ $safeName = $safeParts -join '_'
+
+ # Construire le chemin final
+ $basePath = Join-Path "configs" $system
+ return Join-Path $basePath $safeName
}
# Lire et traiter le fichier de configuration
@@ -161,7 +167,7 @@ foreach ($line in $lines) {
}
} else {
# Pour WSL, vérifier via wsl
- $exists = wsl test -f "$resolvedPath" 2>$null
+ wsl test -f "$resolvedPath" 2>$null | Out-Null
if ($LASTEXITCODE -ne 0) {
Write-Warning "Fichier introuvable dans WSL: $resolvedPath (original: $originalPath)"
$skippedCount++
@@ -182,16 +188,22 @@ foreach ($line in $lines) {
if ($system -eq 'windows') {
Copy-Item -Path $resolvedPath -Destination $projectPath -Force
} else {
- # Pour WSL, utiliser wsl pour copier
- $wslSource = $resolvedPath
- $wslDest = (wsl wslpath -a $projectPath)
- wsl cp "$wslSource" "$wslDest"
- if ($LASTEXITCODE -ne 0) {
- # Fallback: utiliser PowerShell pour copier depuis WSL
- $tempFile = [System.IO.Path]::GetTempFileName()
- wsl cat "$wslSource" | Out-File -FilePath $tempFile -Encoding utf8
- Copy-Item -Path $tempFile -Destination $projectPath -Force
- Remove-Item $tempFile
+ # Pour WSL, utiliser PowerShell pour copier depuis WSL
+ # Méthode plus fiable : lire le contenu depuis WSL et l'écrire avec PowerShell
+ try {
+ $content = wsl cat "$resolvedPath" 2>&1
+ if ($LASTEXITCODE -eq 0) {
+ # Convertir le contenu en chaîne si c'est un tableau
+ if ($content -is [array]) {
+ $content = $content -join "`n"
+ }
+ Set-Content -Path $projectPath -Value $content -Encoding UTF8 -Force
+ } else {
+ throw "Erreur lors de la lecture du fichier WSL: $content"
+ }
+ } catch {
+ Write-Error "Impossible de copier le fichier WSL '$resolvedPath': $_"
+ throw
}
}