Skip to content

Commit

Permalink
Support files with spaces in name (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalten authored Oct 1, 2024
1 parent dd2b0e3 commit 9ea0969
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions appimage/private/mkappdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def to_pseudofile_def_lines(src: Path, dst: Path, preserve_symlinks: bool) -> di
):
operations[dst.as_posix()] = f"s {src.lstat().st_mode & 0o777:o} 0 0 {src.readlink()}"
elif src.is_file():
operations[dst.as_posix()] = f"f {src.lstat().st_mode & 0o777:o} 0 0 cat {src}"
operations[dst.as_posix()] = f'f {src.lstat().st_mode & 0o777:o} 0 0 cat "{src}"'
elif src.is_dir():
operations[dst.as_posix()] = f"d {src.lstat().st_mode & 0o777:o} 0 0"
elif not src.exists():
Expand Down Expand Up @@ -289,7 +289,7 @@ def write_appdir_pseudofile_defs(manifest: Path, apprun: Path, output: Path) ->
"""Write a mksquashfs pf file representing the AppDir."""
lines = [
f"AppRun f 777 0 0 cat {apprun}",
*sorted(f"{k} {v}" for k, v in make_appdir_pseudofile_defs(manifest).items()),
*sorted(f'"{k}" {v}' for k, v in make_appdir_pseudofile_defs(manifest).items()),
"",
]
output.write_text("\n".join(lines))
Expand Down
4 changes: 2 additions & 2 deletions tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ appimage_test(
size = "small",
binary = ":test_py",
data = [
"appimage_data_file.txt",
"appimage data file.txt",
":appimage_data_filegroup",
],
env = {"APPIMAGE_EXTRACT_AND_RUN": "1"}, # Another way to run if no libfuse2 is available
Expand All @@ -122,7 +122,7 @@ appimage(
"zstd",
],
data = [
"appimage_data_file.txt",
"appimage data file.txt",
":appimage_data_filegroup",
],
)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/dir/link_to_file_in_dir2
File renamed without changes.
12 changes: 6 additions & 6 deletions tests/mkappdir_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,26 @@ def cd(path: Path | str) -> Iterator[None]:
def test_to_pseudofile_def_lines() -> None:
mkdef = mkappdir.to_pseudofile_def_lines
with tempfile.TemporaryDirectory() as tmp_dir, cd(tmp_dir):
src = Path("dir/file")
src = Path("dir/space file")
src.parent.mkdir(parents=True, exist_ok=True)
src.touch(0o601)
dangling = Path("dangling")
dangling.symlink_to("../invalid")
link = Path("link")
link = Path("space link")
link.symlink_to(src)

assert mkdef(src, Path("a/b/c/d"), True) == {
"a": "d 755 0 0",
"a/b": "d 755 0 0",
"a/b/c": "d 755 0 0",
"a/b/c/d": "f 601 0 0 cat dir/file",
"a/b/c/d": 'f 601 0 0 cat "dir/space file"',
}
assert mkdef(src, Path("dst"), True) == {"dst": "f 601 0 0 cat dir/file"}
assert mkdef(src, Path("dst"), True) == {"dst": 'f 601 0 0 cat "dir/space file"'}
perms = f"{dangling.lstat().st_mode & 0o777:o}" # default differs on Linux and macOS
assert mkdef(dangling, Path("dst"), True) == {"dst": f"s {perms} 0 0 ../invalid"}
assert mkdef(dangling, Path("dst"), False) == {"dst": f"s {perms} 0 0 ../invalid"}
assert mkdef(link, Path("dst"), True) == {"dst": f"s {perms} 0 0 dir/file"}
assert mkdef(link, Path("dst"), False) == {"dst": f"f {perms} 0 0 cat link"}
assert mkdef(link, Path("dst"), True) == {"dst": f"s {perms} 0 0 dir/space file"}
assert mkdef(link, Path("dst"), False) == {"dst": f'f {perms} 0 0 cat "space link"'}


if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_datadep() -> None:

def test_appimage_datadep() -> None:
"""Test that data deps to the appimage itself are bundled."""
data_dep = Path("tests/appimage_data_file.txt")
data_dep = Path("tests/appimage data file.txt") # note the spaces in the filename
assert data_dep.is_file(), f"{data_dep} does not exist"
assert data_dep.stat().st_size == 13, f"{data_dep} has wrong size {data_dep.stat().st_size}"

Expand Down Expand Up @@ -52,6 +52,7 @@ def test_symlinks() -> None:
"""Test that symlinks are handled correctly."""
link_to_undeclared_dep = Path("tests/dir/link_to_file_in_dir2")
assert link_to_undeclared_dep.is_symlink()
assert link_to_undeclared_dep.readlink().as_posix() == "../dir2/file in dir.txt"
assert not link_to_undeclared_dep.resolve().exists()

link_to_link_to_undeclared_dep = Path("tests/dir/link_to_link_to_file_in_dir2")
Expand Down

0 comments on commit 9ea0969

Please sign in to comment.