-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor cache management and hardlink creation
- Simplified the directory cache retrieval process by removing redundant hardlink checks and streamlining the file path determination. - Introduced utility functions `CachePath` and `WipFile` in `utils.go` to centralize path and temporary file creation logic, improving code reuse and readability. - Updated `CreateLink` in `hardlink.go` to use `CachePath` for consistent path generation. - Removed redundant methods `cachePath` and `wipFile` from `directoryCache`, replacing their functionality with the new utility functions. Signed-off-by: ChengyuZhu6 <[email protected]>
- Loading branch information
1 parent
39666b4
commit b879c95
Showing
3 changed files
with
54 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright The containerd Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cache | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// WipFile creates a temporary file in the given directory with the given key pattern | ||
func WipFile(wipDirectory string, key string) (*os.File, error) { | ||
if err := os.MkdirAll(wipDirectory, 0700); err != nil { | ||
return nil, fmt.Errorf("failed to create wip directory: %w", err) | ||
} | ||
return os.CreateTemp(wipDirectory, key+"-*") | ||
} | ||
|
||
// CachePath returns the path for a cache entry with the given key | ||
func CachePath(directory string, key string) string { | ||
return filepath.Join(directory, key[:2], key) | ||
} |