MCPcopy Index your code
hub / github.com/dagger/dagger / moduleSourceRemoveItems

Method moduleSourceRemoveItems

core/schema/modulesource.go:1783–1882  ·  view source on GitHub ↗

moduleSourceRemoveItems processes removal requests for items (dependencies or toolchains).

(
	ctx context.Context,
	parentSrc *core.ModuleSource,
	removeArgs []string,
	accessor moduleRelationTypeAccessor,
)

Source from the content-addressed store, hash-verified

1781// moduleSourceRemoveItems processes removal requests for items (dependencies or
1782// toolchains).
1783func (s *moduleSourceSchema) moduleSourceRemoveItems(
1784 ctx context.Context,
1785 parentSrc *core.ModuleSource,
1786 removeArgs []string,
1787 accessor moduleRelationTypeAccessor,
1788) (*core.ModuleSource, error) {
1789 parentSrc = parentSrc.Clone()
1790
1791 var filteredItems []dagql.ObjectResult[*core.ModuleSource]
1792 var filteredConfigItems []*modules.ModuleConfigDependency
1793
1794 for i, existingItem := range accessor.getItems(parentSrc) {
1795 existingName := existingItem.Self().ModuleName
1796 var existingSymbolic, existingVersion string
1797
1798 switch existingItem.Self().Kind {
1799 case core.ModuleSourceKindLocal:
1800 if parentSrc.Kind != core.ModuleSourceKindLocal {
1801 return nil, fmt.Errorf("cannot remove local %s from non-local module source kind %s", accessor.typ, parentSrc.Kind)
1802 }
1803 parentSrcRoot := filepath.Join(parentSrc.Local.ContextDirectoryPath, parentSrc.SourceRootSubpath)
1804 itemSrcRoot := filepath.Join(parentSrc.Local.ContextDirectoryPath, existingItem.Self().SourceRootSubpath)
1805 var err error
1806 existingSymbolic, err = pathutil.LexicalRelativePath(parentSrcRoot, itemSrcRoot)
1807 if err != nil {
1808 return nil, fmt.Errorf("failed to get relative path: %w", err)
1809 }
1810
1811 case core.ModuleSourceKindGit:
1812 existingSymbolic = existingItem.Self().Git.CloneRef
1813 if existingItem.Self().SourceRootSubpath != "" {
1814 existingSymbolic += "/" + strings.TrimPrefix(existingItem.Self().SourceRootSubpath, "/")
1815 }
1816 existingVersion = existingItem.Self().Git.Version
1817
1818 default:
1819 return nil, fmt.Errorf("unhandled %s kind: %s", accessor.typ, existingItem.Self().Kind)
1820 }
1821
1822 keep := true
1823 for _, removeArg := range removeArgs {
1824 argSymbolic, argVersion, _ := strings.Cut(removeArg, "@")
1825 argSymbolic = filepath.Clean(argSymbolic)
1826
1827 if argSymbolic != existingName && argSymbolic != existingSymbolic {
1828 continue
1829 }
1830 keep = false
1831
1832 if argVersion == "" {
1833 break
1834 }
1835
1836 if existingVersion == "" {
1837 return nil, fmt.Errorf(
1838 "version %q was requested to be uninstalled but the %s %q was installed without a specific version. Try re-running without specifying the version number",
1839 argVersion,
1840 accessor.typ,

Calls 7

LexicalRelativePathFunction · 0.92
ParseGitRefStringFunction · 0.92
getItemsMethod · 0.80
SelfMethod · 0.80
setItemsMethod · 0.80
matchVersionFunction · 0.70
CloneMethod · 0.65

Tested by

no test coverage detected