Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup wim package for use on non Windows platforms #213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions wim/decompress.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build windows

package wim

import (
Expand Down
5 changes: 0 additions & 5 deletions wim/validate/noop.go

This file was deleted.

46 changes: 22 additions & 24 deletions wim/validate/validate.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,49 @@
// +build windows

package main

import (
"flag"
"fmt"
"os"

"github.com/Microsoft/go-winio/wim"
)

func main() {
flag.Parse()
f, err := os.Open(flag.Arg(0))
if err != nil {
panic(err)
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "usage: %s <WIM>\n", os.Args[0])
os.Exit(1)
}
if err := run(os.Args[1]); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
}

w, err := wim.NewReader(f)
func run(file string) error {
f, err := os.OpenFile(file, os.O_RDONLY, 0)
if err != nil {
panic(err)

return err
}

fmt.Printf("%#v\n%#v\n", w.Image[0], w.Image[0].Windows)

dir, err := w.Image[0].Open()
r, err := wim.NewReader(f)
if err != nil {
panic(err)
return err
}

err = recur(dir)
fmt.Fprintf(os.Stdout, "%#v\n%#v\n", r.Image[0], r.Image[0].Windows)
dir, err := r.Image[0].Open()
if err != nil {
panic(err)
return err
}
return recur(dir)
}

func recur(d *wim.File) error {
files, err := d.Readdir()
func recur(dir *wim.File) error {
files, err := dir.Readdir()
if err != nil {
return fmt.Errorf("%s: %s", d.Name, err)
return fmt.Errorf("cannot read %q: %w", dir.Name, err)
}
for _, f := range files {
if f.IsDir() {
err = recur(f)
if err != nil {
return fmt.Errorf("%s: %s", f.Name, err)
if err := recur(f); err != nil {
return fmt.Errorf("cannot recurse directory %q: %w", f.Name, err)
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions wim/wim.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build windows

// Package wim implements a WIM file parser.
//
// WIM files are used to distribute Windows file system and container images.
Expand Down