mirror of
https://github.com/derfenix/photocatalog.git
synced 2026-03-11 11:52:57 +03:00
38 lines
671 B
Go
38 lines
671 B
Go
package modes
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"sync/atomic"
|
|
)
|
|
|
|
var hardLinkNotSupported = atomic.Bool{}
|
|
|
|
type HardLink struct {
|
|
}
|
|
|
|
func (h HardLink) PlaceIt(sourcePath, targetPath string, mode os.FileMode) error {
|
|
if hardLinkNotSupported.Load() {
|
|
if copyErr := (Copy{}).PlaceIt(sourcePath, targetPath, mode); copyErr != nil {
|
|
return copyErr
|
|
}
|
|
}
|
|
|
|
if err := os.Link(sourcePath, targetPath); err != nil {
|
|
if os.IsExist(err) {
|
|
return nil
|
|
}
|
|
|
|
log.Println("Create hardlink failed:", err.Error())
|
|
hardLinkNotSupported.Store(true)
|
|
|
|
if copyErr := (Copy{}).PlaceIt(sourcePath, targetPath, mode); copyErr != nil {
|
|
return copyErr
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
return nil
|
|
}
|