Forbid adding duplicated namespace#1169
Forbid adding duplicated namespace#1169yummypeng wants to merge 1 commit intoopencontainers:masterfrom
Conversation
Signed-off-by: Yuanhong Peng <pengyuanhong@huawei.com>
8a8d6d0 to
aa06c0a
Compare
| } | ||
| (*n)[i].Path = path | ||
| return false | ||
| } |
There was a problem hiding this comment.
You haven't changed any of the callers of .Add to check the return value, so we're now ignoring duplicates. Please fix that.
There was a problem hiding this comment.
I don't think this is right.
This function is not only for adding new namespaces, but also for modifying path of existing namespace, you shouldn't disable this function. Also as @cyphar said, you didn't modify any caller so the return false/true is meaningless.
There was a problem hiding this comment.
Except the code I quoted before, I only find the callers of Add() in some test code. I know that this function is also used for modifying path of existing namespace, but I still think it would be better that if we want to modify path of existing namespace, we should remove it first, and then add it. If this idea is acceptable, I will fix those test functions then.
There was a problem hiding this comment.
Hmmmm.....If we must remove and then add to modify path of an existing namespace, then I think we won't need any check in Add().
There was a problem hiding this comment.
Actually, I'm confused. The code you quoted already doesn't allow for duplicate namespaces -- what's the benefit of this PR (it also appears to have broken the tests)?
There was a problem hiding this comment.
At the beginning, I just mistakenly thought the last line of code in Add() is redundant. But now it seems that my PR is meaningless and it's better to remain unchanged. Thanks for all your comments. I will close this PR later.
We now forbid duplicated namespace in spec(#1150), if there is a duplicated namespace, then it'll just return with error in
CreateLibcontainerConfig():So, as far as I can see, the last line of code in
Add()will never be reached here. Therefore, I just modified this func to be consistent withRemove(). Besides, this modification also forbids adding duplicated namespace to make the logic more clear.Signed-off-by: Yuanhong Peng pengyuanhong@huawei.com