mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
TestRenameIfExists used os.CreateTemp(os.TempDir(), …) and then renamed back over the original path. On the release runner that second rename returns EPERM — the shared sticky /tmp is not a place to exercise overwrite semantics, and a collision there fails a release for reasons that have nothing to do with the code under test. It is now isolated in t.TempDir(). This is what failed the v1.37.12 release build; v1.37.11 failed the same way. Co-authored-by: Hanzo Dev <[email protected]>
43 lines
843 B
Go
43 lines
843 B
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package filesystem
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRenameIfExists(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
t.Parallel()
|
|
|
|
dir := t.TempDir()
|
|
a := filepath.Join(dir, "a")
|
|
b := filepath.Join(dir, "b")
|
|
|
|
f, err := os.Create(a)
|
|
require.NoError(err)
|
|
require.NoError(f.Close())
|
|
|
|
// rename "a" to "b"
|
|
renamed, err := RenameIfExists(a, b)
|
|
require.NoError(err)
|
|
require.True(renamed)
|
|
|
|
// rename "b" to "a"
|
|
renamed, err = RenameIfExists(b, a)
|
|
require.NoError(err)
|
|
require.True(renamed)
|
|
|
|
// remove "a", but rename "a"->"b" should NOT error
|
|
require.NoError(os.RemoveAll(a))
|
|
renamed, err = RenameIfExists(a, b)
|
|
require.NoError(err)
|
|
require.False(renamed)
|
|
}
|