Skip to content

Commit

Permalink
Include files relative to parent (fixes #11)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Blichmann <mail@blichmann.eu>
  • Loading branch information
cblichmann committed Dec 9, 2018
1 parent 1d73194 commit 33fad57
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ jailtime (0.7-1) unstable; urgency=medium

* New --dry-run option to print actions only
* Put run statements last, do not sort them
* Fix: Include files relative to their parent

-- Christian Blichmann (Secure Email 2018/2019) <mail@blichmann.eu> Mon, 26 Nov 2018 23:24:34 +0100

Expand Down
4 changes: 2 additions & 2 deletions jailtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"flag"
"fmt"
"os"
"path"
"path/filepath"

"blichmann.eu/code/jailtime/action"
"blichmann.eu/code/jailtime/copy"
Expand Down Expand Up @@ -149,7 +149,7 @@ func updateChroot(chrootDir string, stmts spec.Statements) (err error) {
reflinkOpt = copy.ReflinkAlways
}
for _, s := range spec.ExpandLexical(expandWithDependencies(stmts)) {
target := path.Join(chrootDir, s.Target())
target := filepath.Join(chrootDir, s.Target())
if *verbose {
fmt.Println(s.Verbose())
if *dryRun {
Expand Down
6 changes: 3 additions & 3 deletions spec/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
package spec // import "blichmann.eu/code/jailtime/spec"

import (
"path"
"path/filepath"
"sort"
)

Expand Down Expand Up @@ -57,7 +57,7 @@ func ExpandLexical(stmts Statements) Statements {
done[target] = true
if dir != target {
expanded = append(expanded, s)
dir = path.Dir(target)
dir = filepath.Dir(target)
}
for dirLen := 0; dirLen != len(dir) && dir != "/"; {
if _, ok := done[dir]; !ok {
Expand All @@ -72,7 +72,7 @@ func ExpandLexical(stmts Statements) Statements {
done[dir] = true
}
dirLen = len(dir)
dir = path.Dir(dir)
dir = filepath.Dir(dir)
}
}
sort.Stable(expanded)
Expand Down
13 changes: 12 additions & 1 deletion spec/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"bufio"
"fmt"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -179,6 +180,15 @@ func parseFromFile(filename string, includeDepth int) (stmts Statements,
return
}

fromDir, err := filepath.EvalSymlinks(filename)
if err != nil {
return
}
if fromDir, err = filepath.Abs(fromDir); err != nil {
return
}
fromDir = filepath.Dir(fromDir)

f, err := os.Open(filename)
if err != nil {
return
Expand All @@ -194,7 +204,8 @@ func parseFromFile(filename string, includeDepth int) (stmts Statements,
line = s.Text()
lineStmts, err = parseSpecLine(filename, lineNo, line,
func(filename string) (Statements, error) {
return parseFromFile(filename, includeDepth+1)
return parseFromFile(filepath.Join(fromDir, filename),
includeDepth+1)
})
if err != nil {
return
Expand Down

0 comments on commit 33fad57

Please sign in to comment.