summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-12-12 09:45:18 +0000
committerLars Wirzenius <liw@liw.fi>2020-12-12 09:45:18 +0000
commitcf529f12223f571739ae33a4e2e9d31c27ba692d (patch)
tree156f23311b1e2ceabb069dd46bd4af871f5005d3
parent0e3bec381d9c1a04448b62483d1635961ca3b3d3 (diff)
parent79183fab131b0e426abf647472469aed160e66f7 (diff)
downloadsummain-rs-cf529f12223f571739ae33a4e2e9d31c27ba692d.tar.gz
Merge branch 'symlink' into 'main'
feat: support symbolic links See merge request larswirzenius/summain!12
-rw-r--r--src/lib.rs9
-rw-r--r--subplot/summain.py12
-rw-r--r--subplot/summain.yaml3
-rw-r--r--summain.md27
4 files changed, 46 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index fee2a96..7db1115 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -31,8 +31,8 @@
use serde::Serialize;
use sha2::{Digest, Sha256};
-use std::fs::symlink_metadata;
use std::fs::File;
+use std::fs::{read_link, symlink_metadata};
use std::io::{BufReader, Read};
use std::os::linux::fs::MetadataExt;
use std::path::{Path, PathBuf};
@@ -50,6 +50,7 @@ pub struct ManifestEntry {
nlink: u64,
size: Option<u64>,
sha256: Option<String>,
+ target: Option<PathBuf>,
}
impl ManifestEntry {
@@ -66,6 +67,11 @@ impl ManifestEntry {
} else {
None
};
+ let target = if m.file_type().is_symlink() {
+ Some(read_link(path)?)
+ } else {
+ None
+ };
Ok(Self {
path: path.to_path_buf(),
mode: m.st_mode(),
@@ -74,6 +80,7 @@ impl ManifestEntry {
nlink: m.st_nlink(),
size: if m.is_dir() { None } else { Some(m.st_size()) },
sha256: hash,
+ target,
})
}
}
diff --git a/subplot/summain.py b/subplot/summain.py
index 98eecf2..4efc8c4 100644
--- a/subplot/summain.py
+++ b/subplot/summain.py
@@ -17,14 +17,18 @@ def create_file(ctx, filename=None):
open(filename, "w").close()
+def create_symlink(ctx, linkname=None, target=None):
+ os.symlink(target, linkname)
+
+
def set_atime(ctx, filename=None, timestamp=None):
st = os.lstat(filename)
- os.utime(filename, (int(timestamp), int(st.st_mtime)))
+ os.utime(filename, (int(timestamp), int(st.st_mtime)), follow_symlinks=False)
def set_mtime(ctx, filename=None, timestamp=None):
st = os.lstat(filename)
- os.utime(filename, (int(st.st_atime), int(timestamp)))
+ os.utime(filename, (int(st.st_atime), int(timestamp)), follow_symlinks=False)
def output_matches_file(ctx, filename=None):
@@ -35,6 +39,6 @@ def output_matches_file(ctx, filename=None):
actual = runcmd_get_stdout(ctx)
expected = get_file(filename).decode("UTF-8")
logging.debug("output_matches:")
- logging.debug(f" actual: {actual!r}")
- logging.debug(f" expect: {expected!r}")
+ logging.debug(f" actual:\n{actual}")
+ logging.debug(f" expect:\n{expected}")
assert_eq(actual, expected)
diff --git a/subplot/summain.yaml b/subplot/summain.yaml
index 31bc28c..2fd12a5 100644
--- a/subplot/summain.yaml
+++ b/subplot/summain.yaml
@@ -7,6 +7,9 @@
- given: file {filename}
function: create_file
+- given: symlink {linkname} pointing at {target}
+ function: create_symlink
+
- given: atime for {filename} is {timestamp}
function: set_atime
diff --git a/summain.md b/summain.md
index 4652c7e..db22d04 100644
--- a/summain.md
+++ b/summain.md
@@ -85,6 +85,7 @@ mtime_nsec: 0
nlink: 2
size: ~
sha256: ~
+target: ~
```
## Writeable file
@@ -108,6 +109,7 @@ mtime_nsec: 0
nlink: 1
size: 0
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
+target: ~
```
## Read-only file
@@ -130,6 +132,7 @@ mtime_nsec: 0
nlink: 1
size: 0
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
+target: ~
```
## Two files sorted
@@ -154,6 +157,7 @@ mtime_nsec: 0
nlink: 1
size: 0
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
+target: ~
---
path: bbb
mode: "-r--r--r--"
@@ -162,6 +166,29 @@ mtime_nsec: 0
nlink: 1
size: 0
sha256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
+target: ~
+```
+
+## Symlink
+
+~~~scenario
+given an installed summain
+given symlink ccc pointing at aaa
+and mtime for ccc is 44
+when I run summain ccc
+then output matches file ccc.yaml
+~~~
+
+```{#ccc.yaml .file .numberLines}
+---
+path: ccc
+mode: lrwxrwxrwx
+mtime: 44
+mtime_nsec: 0
+nlink: 1
+size: 3
+sha256: ~
+target: aaa
```
---