#Go SDK - git directory Entries of all subdirectories recursively?

1 messages · Page 1 of 1 (latest)

lunar flare
#

Hey guys,

moving my question from #general so it doesn't get lost in there.

I want to list all files and directories in my git repo with dagger, calling Entries on *dagger.Directory, and it doesn't return all files and directories recursively. Which is not surprising, just wanted to ask if anyone thought about how to get all entries recursively? I only get current directory files and subdirectories.

My code looks something like this

readme, err := client.
        Git("git@private-repository.git").
        Branch("main").
        Tree(
            dagger.GitRefTreeOpts{
                SSHAuthSocket: client.Host().UnixSocket(sshAgentPath),
            },
        ).
        Directory("docs").
        Entries(ctx)

What I'm aiming at is to list the file paths, if there are files of specific name I exclude them from the directory, ideally using WithoutFile, then Export the directory to host workdir.

#

@dusky bison you suggested to use find <path>, in shell I suppose?

dusky bison
#

The find command need to be in the container, yes

lunar flare
#

So there is most likely no way to do this without first saving the directory to local filesystem where the pipeline runs

dusky bison
#

yes there is, gimme 1 sec

#
package main

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

func main() {
    ctx := context.Background()
    client, err := dagger.Connect(ctx)
    if err != nil {
        panic(err)
    }
    defer client.Close()

    docsDir := client.
        Git("github.com/dagger/dagger").
        Branch("main").
        Tree().
        Directory("docs")

      out, err := client.Container().
        From("alpine").
        WithMountedDirectory("/docs", docsDir).WithExec([]string{"find", "/docs"}).Stdout(ctx)
        
    
    if err != nil {
        panic(err)
    }
    fmt.Println(out)
  
}

^ that should work

lunar flare
#

Oh yes, I sometimes forget that I can simply mount it to container and work with it there. I'm still exploring dagger and it's options. This looks good

dusky bison
#

happy to help!

lunar flare
#

Thank you for your help

dusky bison
#

anytime! looking forward to see what you'll build with it!

lunar flare
#

So I can then rely on tools that are available inside the containers I mount the directory in. Does that mean that if I wanted to use something like os.ReadDir and have the scanning logic implemented in Go, I can't simply execute that in the same running code?

#

Or am I overthinking this

dusky bison
lunar flare
#

I'm using the find command in the end, only had to use the debian image since find in alpine doesn't support complex output formatting and that does it for me since I only need to separate directories and files and trim the directory that is being scanned from the output paths

#

It's been great to be honest, reliable and easy to work with, I just have to learn to think more outside of the box with dagger