feat: optimize disk mount logic

This commit is contained in:
zhengkunwang223 2025-12-30 10:45:01 +08:00
parent e3dea80cb7
commit 2ebe5addde
12 changed files with 39 additions and 2 deletions

View file

@ -463,6 +463,11 @@ func isPointMounted(mountPoint string) bool {
}
func addToFstabWithOptions(device, mountPoint, filesystem, options string) error {
uuid, err := getDeviceUUID(device)
if err != nil {
return fmt.Errorf("failed to get UUID for device %s: %v", device, err)
}
if filesystem == "" {
fsType, err := getFilesystemType(device)
if err != nil {
@ -476,7 +481,7 @@ func addToFstabWithOptions(device, mountPoint, filesystem, options string) error
options = "defaults"
}
entry := fmt.Sprintf("%s %s %s %s 0 2\n", device, mountPoint, filesystem, options)
entry := fmt.Sprintf("UUID=%s %s %s %s 0 2\n", uuid, mountPoint, filesystem, options)
file, err := os.OpenFile("/etc/fstab", os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
@ -568,3 +573,15 @@ func parseSizeToBytes(sizeStr string) int64 {
return val
}
}
func getDeviceUUID(device string) (string, error) {
output, err := cmd.RunDefaultWithStdoutBashC(fmt.Sprintf("blkid -s UUID -o value %s", device))
if err != nil {
return "", err
}
uuid := strings.TrimSpace(output)
if uuid == "" {
return "", fmt.Errorf("no UUID found for device %s", device)
}
return uuid, nil
}

View file

@ -2755,6 +2755,8 @@ const message = {
streamPortsHelper:
'Set the external listening port number, clients will access the service through this port, separated by commas, e.g., 5222,5223',
streamHelper: 'TCP/UDP Port Forwarding and Load Balancing',
syncHtmlHelper: 'Sync to PHP and static websites',
},
php: {
short_open_tag: 'Short tag support',

View file

@ -2747,6 +2747,8 @@ const message = {
streamPortsHelper:
'Configura el número de puerto de escucha externo, los clientes accederán al servicio a través de este puerto, separado por comas, p. ej., 5222,5223',
streamHelper: 'Reenvío de Puertos y Balanceo de Carga TCP/UDP',
syncHtmlHelper: 'Sincronizar con PHP y sitios web estáticos',
},
php: {
short_open_tag: 'Soporte de etiquetas cortas',

View file

@ -2679,6 +2679,8 @@ const message = {
streamPortsHelper:
'外部リスニングポート番号を設定しますクライアントはこのポートを通じてサービスにアクセスしますカンマで区切ってください5222,5223',
streamHelper: 'TCP/UDP ポート転送とロードバランシング',
syncHtmlHelper: 'PHP と静的ウェブサイトに同期',
},
php: {
short_open_tag: '短いタグサポート',

View file

@ -2634,6 +2634,8 @@ const message = {
streamPortsHelper:
'외부 수신 포트 번호를 설정합니다. 클라이언트는 포트를 통해 서비스에 액세스합니다. 쉼표로 구분하세요. : 5222,5223',
streamHelper: 'TCP/UDP 포트 포워딩 로드 밸런싱',
syncHtmlHelper: 'PHP 정적 웹사이트에 동기화',
},
php: {
short_open_tag: '짧은 태그 지원',

View file

@ -2736,6 +2736,8 @@ const message = {
streamPortsHelper:
'Tetapkan nombor port pendengaran luaran, pelanggan akan mengakses perkhidmatan melalui port ini, dipisahkan dengan koma, cth., 5222,5223',
streamHelper: 'Penerusan Port dan Pengimbangan Beban TCP/UDP',
syncHtmlHelper: 'Segerakkan ke PHP dan laman web statik',
},
php: {
short_open_tag: 'Sokongan tag pendek',

View file

@ -2741,6 +2741,8 @@ const message = {
streamPortsHelper:
'Defina o número da porta de escuta externa, os clientes acessarão o serviço através desta porta, separados por vírgulas, por exemplo: 5222,5223',
streamHelper: 'Encaminhamento de Portas e Balanceamento de Carga TCP/UDP',
syncHtmlHelper: 'Sincronizar com PHP e sites estáticos',
},
php: {
short_open_tag: 'Suporte para short tags',

View file

@ -2736,6 +2736,8 @@ const message = {
streamPortsHelper:
'Установите номер внешнего порта прослушивания, клиенты будут получать доступ к службе через этот порт, разделяйте запятыми, например: 5222,5223',
streamHelper: 'Перенаправление портов и балансировка нагрузки TCP/UDP',
syncHtmlHelper: 'Синхронизировать с PHP и статическими сайтами',
},
php: {
short_open_tag: 'Поддержка коротких тегов',

View file

@ -2793,6 +2793,8 @@ const message = {
streamPortsHelper:
'Harici dinleme bağlantı noktası numarasını ayarlayın, istemciler bu bağlantı noktası üzerinden hizmete erişecektir, virgülle ayırın, örn.: 5222,5223',
streamHelper: 'TCP/UDP Port Yönlendirme ve Yük Dengeleme',
syncHtmlHelper: 'PHP ve statik web siteleriyle senkronize et',
},
php: {
short_open_tag: 'Kısa etiket desteği',

View file

@ -2565,6 +2565,8 @@ const message = {
streamPorts: '監聽端口',
streamPortsHelper: '設定對外監聽的埠號客戶端將透過此埠存取服務按逗號分割例如5222,5223',
streamHelper: 'TCP/UDP 端口轉發與負載均衡',
syncHtmlHelper: '同步到 PHP 和靜態網站',
},
php: {
short_open_tag: '短標籤支援',

View file

@ -2562,6 +2562,8 @@ const message = {
streamPorts: '监听端口',
streamPortsHelper: '设置对外监听的端口号客户端将通过此端口访问服务按逗号分割例如5222,5223',
streamHelper: 'TCP/UDP 端口转发与负载均衡',
syncHtmlHelper: '同步到 PHP 和静态网站',
},
php: {
short_open_tag: '短标签支持',

View file

@ -13,7 +13,7 @@
</el-text>
</div>
<div class="mt-1.5">
<el-checkbox v-model="req.sync">{{ $t('同步到 PHP 和静态网站') }}</el-checkbox>
<el-checkbox v-model="req.sync">{{ $t('website.syncHtmlHelper') }}</el-checkbox>
</div>
<div ref="htmlRef" class="default-html"></div>