#Using ignore when passing directory with a constructor seems to be ignore

1 messages · Page 1 of 1 (latest)

gaunt oracle
#

i have a constructor that take a directory, i tried to add the ignore comment but it seems to be ignore. Here you can repoduce with this i think

package main

import (
    "context"
    "fmt"
    "dagger.io/dagger":*
)

func New(
    // ignore only *.ignore files
    // +ignore=["**/*.ignore"]
    dir *dagger.Directory,
) *MyModule {
    return &MyModule{
        Dir: dir,
    }
}

type MyModule struct {
    Dir *dagger.Directory
}

// Count remaining files after ignore rules are applied
func (m *MyModule) FileCount(ctx context.Context) (int, error) {
    files, err := m.Dir.Entries(ctx)
    if err != nil {
        return 0, err
    }
    return len(files), nil
}

// Another function taking a second directory, also ignoring *.ignore
func (m *MyModule) CompareCounts(
    ctx context.Context,
    // +ignore=["**/*.ignore"]
    other *dagger.Directory,
) (string, error) {

    mainCount, err := m.FileCount(ctx)
    if err != nil {
        return "", err
    }

    otherFiles, err := other.Entries(ctx)
    if err != nil {
        return "", err
    }

    return fmt.Sprintf(
        "Module directory: %d files, provided directory: %d files",
        mainCount, len(otherFiles),
    ), nil
}

fair badge
#

@gaunt oracle seems like the issue is that you're importing the types from "dagger.io/dagger" instead of dagger/my-module/internal/dagger

#

your module should use the types generated by dagger develop, not importing them from the public dagger.io go package

#

changing that fixes it

gaunt oracle
#

oh indeed, in this example you're right but in my real world use case i have the correct import

#

i'll try to really reproduce

fair badge
# gaunt oracle oh indeed, in this example you're right but in my real world use case i have the...

in a real case scenario it works for me.

marcos:tmp/ignore (⎈ |N/A)$ ls
dagger.gen.go  dagger.json  go.mod  go.sum  internal  LICENSE  main.go  test.ignore
130|marcos:tmp/ignore (⎈ |N/A)$ dagger call --dir . file-count
â–¶ connect 0.2s
â–¶ load module: . 0.9s
✔ parsing command line arguments 0.0s

✔ myModule(
  ┆ dir: Address.directory: Directory!
  ): MyModule! 1.9s
â–¶ .fileCount: [String!]! 0.3s

.gitattributes
.gitignore
LICENSE
dagger.gen.go
dagger.json
go.mod
go.sum
internal/
main.go

^ as you can see the test.ignore file is not there

#

I've changed the file-count function so it prints the dir.Entries directly instead of returning the count

gaunt oracle
#

it is correctly ignore indeed what i'm seeing is that it first does copy without ignore
here the logs with constructor

â–¼ parsing command line arguments 0.0s
├╴✔ address(value: "."): Address! = xxh3:5a5b27c0384d4808 0.0s
├╴▼ .directory: Directory! = xxh3:182acd16224dc7bc 0.0s
│ ╰╴▼ Host.directory(path: "."): Directory! = xxh3:0504aad3f10d2b86 0.0s
│   ╰╴▼ filesync 0.0s
│     ╰╴✔ copy 0.0s
│
â•°â•´â–¼ Address.directory(exclude: ["**/*.ignore"]): Directory! = xxh3:22605bf8125ecc8e 0.0s
  â•°â•´â–¼ Host.directory(path: ".", exclude: ["**/*.ignore"]): Directory! = xxh3:ca5259121fe9024b 0.0s
    â•°â•´â–¼ filesync 0.0s
      ╰╴✔ copy 0.0s

â–¼ daggerIgnore(
│ ┆ dir: Address.directory: Directory! = xxh3:182acd16224dc7bc
│ ): DaggerIgnore! = xxh3:52f71a22234624d7 0.0s
├╴✔ directory: Directory! = xxh3:c43973d83a6a533a 0.0s
├╴✔ .withDirectory(
│   ┆ path: "/"
│   ┆ source: Address.directory: Directory! = xxh3:182acd16224dc7bc
│   ┆ exclude: ["**/*.ignore"]
│   ): Directory! = xxh3:7cc06c482f746cf3 0.0s

And then if i remove the constructor

â–¼ parsing command line arguments 0.9s
├╴✔ address(value: "."): Address! = xxh3:5a5b27c0384d4808 0.0s
â•°â•´â–¼ .directory(exclude: ["**/*.ignore"]): Directory! = xxh3:7bae6905cfaa89ae 0.9s
  â•°â•´â–¼ Host.directory(path: ".", exclude: ["**/*.ignore"]): Directory! = xxh3:20c716b12647b626 0.9s
    â•°â•´â–¼ filesync 0.9s
      ╰╴✔ copy 0.9s

✔ daggerIgnore: DaggerIgnore! = xxh3:f6114027cf7ee81e 0.0s
â–¼ .compareCounts(
│ ┆ other: Address.directory(exclude: ["**/*.ignore"]): Directory! = xxh3:7bae6905cfaa89ae
│ ): String! = xxh3:166842ce2c57810a 2.0s ERROR
  ✔ directory: Directory! = xxh3:c43973d83a6a533a 0.0s
  ✔ .withDirectory(
    ┆ path: "/"
    ┆ source: Address.directory(exclude: ["**/*.ignore"]): Directory! = xxh3:7bae6905cfaa89ae
    ┆ exclude: ["**/*.ignore"]
    ): Directory! = xxh3:adcc61228f8a8254 0.0s

There is this Host.directory(path: "."): without any ignore info in the first one

#

and this is copying the entire folder