Skip to content

Commit 24b1939

Browse files
committed
git media [clean | smudge] vs git-media-clean
1 parent 4e24860 commit 24b1939

File tree

3 files changed

+80
-37
lines changed

3 files changed

+80
-37
lines changed

commands/command_clean.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package gitmedia
2+
3+
import (
4+
".."
5+
"../filters"
6+
"os"
7+
)
8+
9+
type CleanCommand struct {
10+
*Command
11+
}
12+
13+
func (c *CleanCommand) Run() {
14+
var filename string
15+
if len(c.Args) > 1 {
16+
filename = c.Args[1]
17+
} else {
18+
filename = ""
19+
}
20+
21+
cleaned, err := gitmediafilters.Clean(os.Stdin)
22+
if err != nil {
23+
gitmedia.Panic(err, "Error cleaning asset")
24+
}
25+
defer cleaned.Close()
26+
27+
tmpfile := cleaned.File.Name()
28+
mediafile := gitmedia.LocalMediaPath(cleaned.Sha)
29+
if stat, _ := os.Stat(mediafile); stat != nil {
30+
if stat.Size() != cleaned.Size {
31+
gitmedia.Exit("Files don't match:\n%s\n%s", mediafile, tmpfile)
32+
}
33+
gitmedia.Debug("%s exists", mediafile)
34+
} else {
35+
if err := os.Rename(tmpfile, mediafile); err != nil {
36+
gitmedia.Panic(err, "Unable to move %s to %s\n", tmpfile, mediafile)
37+
}
38+
39+
gitmedia.QueueUpload(cleaned.Sha, filename)
40+
gitmedia.Debug("Writing %s", mediafile)
41+
}
42+
43+
gitmedia.Encode(os.Stdout, cleaned.Sha)
44+
}
45+
46+
func init() {
47+
registerCommand("clean", func(c *Command) RunnableCommand {
48+
return &CleanCommand{Command: c}
49+
})
50+
}

commands/command_media.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

commands/command_smudge.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package gitmedia
2+
3+
import (
4+
".."
5+
"../filters"
6+
"os"
7+
)
8+
9+
type SmudgeCommand struct {
10+
*Command
11+
}
12+
13+
func (c *SmudgeCommand) Run() {
14+
sha, err := gitmedia.Decode(os.Stdin)
15+
if err != nil {
16+
gitmedia.Panic(err, "Error reading git-media meta data from stdin:")
17+
}
18+
19+
err = gitmediafilters.Smudge(os.Stdout, sha)
20+
if err != nil {
21+
smudgerr := err.(*gitmediafilters.SmudgeError)
22+
gitmedia.Panic(err, "Error reading file from local media dir: %s", smudgerr.Filename)
23+
}
24+
}
25+
26+
func init() {
27+
registerCommand("smudge", func(c *Command) RunnableCommand {
28+
return &SmudgeCommand{Command: c}
29+
})
30+
}

0 commit comments

Comments
 (0)