Fix bug in subscriptions file save#1436
Closed
saschagrunert wants to merge 1 commit into
Closed
Conversation
We have to keep the `filepath.Dir` since it has been added on purpose. Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: saschagrunert The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Merged
Member
|
I also found it just now, WDYT about: diff --git a/pkg/subscriptions/subscriptions.go b/pkg/subscriptions/subscriptions.go
index c21f5ecc..b751f487 100644
--- a/pkg/subscriptions/subscriptions.go
+++ b/pkg/subscriptions/subscriptions.go
@@ -27,9 +27,10 @@ var (
UserOverrideMountsFile = filepath.Join(os.Getenv("HOME"), ".config/containers/mounts.conf")
)
-// subscriptionData stores the name of the file and the content read from it
+// subscriptionData stores the relative name of the file and the content read from it
type subscriptionData struct {
- name string
+ // relPath is the relative path to the file
+ relPath string
data []byte
mode os.FileMode
dirMode os.FileMode
@@ -37,10 +38,13 @@ type subscriptionData struct {
// saveTo saves subscription data to given directory
func (s subscriptionData) saveTo(dir string) error {
- if err := umask.MkdirAllIgnoreUmask(dir, s.dirMode); err != nil {
+ // We need to join the path here and create all parent directories, only
+ // creating dir is not good enough as relPath could also contain directories.
+ path := filepath.Join(dir, s.relPath)
+ if err := umask.MkdirAllIgnoreUmask(filepath.Dir(path), s.dirMode); err != nil {
return fmt.Errorf("create subscription directory: %w", err)
}
- if err := umask.WriteFileIgnoreUmask(filepath.Join(dir, s.name), s.data, s.mode); err != nil {
+ if err := umask.WriteFileIgnoreUmask(path, s.data, s.mode); err != nil {
return fmt.Errorf("write subscription data: %w", err)
}
return nil
@@ -96,7 +100,7 @@ func readFileOrDir(root, name string, parentMode os.FileMode) ([]subscriptionDat
return nil, err
}
return []subscriptionData{{
- name: name,
+ relPath: name,
data: bytes,
mode: s.Mode(),
dirMode: parentMode,Because name is not really a name but a relative path instead. This should prevent others from making the same mistake again. |
Member
|
I created #1437 with my diff + added a test. I think this makes it more clear. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We have to keep the
filepath.Dirsince it has been added on purpose.Follow-up on #1421