-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement namespaces, clean up context use
More of general cleanup/refactoring, no new features. Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
- Loading branch information
Showing
24 changed files
with
444 additions
and
172 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. | ||
# | ||
# Generated on 2020-09-25T18:15:38Z by kres ce6bee5-dirty. | ||
|
||
policies: | ||
- type: commit | ||
spec: | ||
dco: true | ||
gpg: false | ||
spellcheck: | ||
locale: US | ||
maximumOfOneCommit: true | ||
header: | ||
length: 89 | ||
imperative: true | ||
case: lower | ||
invalidLastCharacters: . | ||
body: | ||
required: true | ||
conventional: | ||
types: ["chore","docs","perf","refactor","style","test","release"] | ||
scopes: ["*"] | ||
- type: license | ||
spec: | ||
skipPaths: | ||
- .git/ | ||
includeSuffixes: | ||
- .go | ||
excludeSuffixes: | ||
- .pb.go | ||
header: | | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. |
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
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 |
---|---|---|
@@ -1,70 +1,74 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
//nolint: golint | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/talos-systems/os-runtime/pkg/resource" | ||
) | ||
|
||
const PathResourceType = resource.Type("os/path") | ||
|
||
type pathResourceSpec struct { | ||
dependents []string | ||
} | ||
|
||
// PathResource represents a path in the filesystem. | ||
// | ||
// Resource ID is the path, and dependents are all the immediate | ||
// children on the path. | ||
type PathResource struct { | ||
path string | ||
version int | ||
dependents []string | ||
md resource.Metadata | ||
spec pathResourceSpec | ||
} | ||
|
||
func NewPathResource(path string) *PathResource { | ||
return &PathResource{path: path} | ||
} | ||
|
||
func (path *PathResource) ID() resource.ID { | ||
return path.path | ||
} | ||
func NewPathResource(ns resource.Namespace, path string) *PathResource { | ||
r := &PathResource{ | ||
md: resource.NewMetadata(ns, PathResourceType, path, resource.VersionUndefined), | ||
} | ||
r.md.BumpVersion() | ||
|
||
func (path *PathResource) Type() resource.Type { | ||
return PathResourceType | ||
return r | ||
} | ||
|
||
func (path *PathResource) Version() resource.Version { | ||
return strconv.Itoa(path.version) | ||
func (path *PathResource) Metadata() resource.Metadata { | ||
return path.md | ||
} | ||
|
||
func (path *PathResource) Spec() interface{} { | ||
return nil | ||
return path.spec | ||
} | ||
|
||
func (path *PathResource) String() string { | ||
return fmt.Sprintf("PathResource(%q)", path.path) | ||
return fmt.Sprintf("PathResource(%q)", path.md.ID()) | ||
} | ||
|
||
func (path *PathResource) Copy() resource.Resource { | ||
return &PathResource{ | ||
path: path.path, | ||
version: path.version, | ||
dependents: append([]string(nil), path.dependents...), | ||
md: path.md, | ||
spec: pathResourceSpec{ | ||
dependents: append([]string(nil), path.spec.dependents...), | ||
}, | ||
} | ||
} | ||
|
||
func (path *PathResource) AddDependent(dependent *PathResource) { | ||
path.dependents = append(path.dependents, dependent.path) | ||
path.version++ | ||
path.spec.dependents = append(path.spec.dependents, dependent.md.ID()) | ||
path.md.BumpVersion() | ||
} | ||
|
||
func (path *PathResource) DropDependent(dependent *PathResource) { | ||
for i, p := range path.dependents { | ||
if p == dependent.path { | ||
path.dependents = append(path.dependents[:i], path.dependents[i+1:]...) | ||
for i, p := range path.spec.dependents { | ||
if p == dependent.md.ID() { | ||
path.spec.dependents = append(path.spec.dependents[:i], path.spec.dependents[i+1:]...) | ||
|
||
break | ||
} | ||
} | ||
|
||
path.version++ | ||
path.md.BumpVersion() | ||
} |
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
Oops, something went wrong.