Skip to content

Commit

Permalink
Merge pull request #30 from tamada/release/v0.5.2
Browse files Browse the repository at this point in the history
Release/v0.5.2
  • Loading branch information
tamada authored Aug 2, 2024
2 parents 24f3f1b + 5c26dea commit 8e34824
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 68 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/update-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
run: |
sed "s/^version = \".*\"/version = \"${{ steps.vars.outputs.tag }}\"/" Cargo.toml > a ; mv a Cargo.toml
sed "s/\$VERSION/${{ steps.vars.outputs.tag }}/g" templates/README.md > a ; mv a README.md
sed "s/ARG VERSION=.*/ARG VERSION=${{ steps.vars.outputs.tag }}/g" Dockerfile > a ; mv a Dockerfile
for i in $(find dockers -name Dockerfile); do
sed "s/ARG VERSION=.*/ARG VERSION=${{ steps.vars.outputs.tag }}/g" $i > a ; mv a $i
done
- name: Initialize Git
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "totebag"
version = "0.5.0"
version = "0.5.2"
description = "A tool for extracting/archiving files and directories in multiple formats."
repository = "https://github.com/tamada/totebag"
readme = "README.md"
Expand Down
29 changes: 0 additions & 29 deletions Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions Dockerfile
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# totebag

[![Version](https://shields.io/badge/Version-0.5.0-blue)](https://github.com/tamada/totebag/releases/tag/v0.5.0)
[![Version](https://shields.io/badge/Version-0.5.2-blue)](https://github.com/tamada/totebag/releases/tag/v0.5.2)
[![MIT License](https://shields.io/badge/License-MIT-blue)](https://github.com/tamada/totebag/blob/main/LICENSE)
[![docker](https://shields.io/badge/Docker-0.5.0-blue?logo=docker)](https://github.com/tamada/totebag/pkgs/container/totebag)
[![docker](https://shields.io/badge/Docker-0.5.2-blue?logo=docker)](https://github.com/tamada/totebag/pkgs/container/totebag)

[![build](https://github.com/tamada/totebag/actions/workflows/build.yaml/badge.svg)](https://github.com/tamada/totebag/actions/workflows/build.yaml)
[![Rust Report Card](https://rust-reportcard.xuri.me/badge/github.com/tamada/totebag)](https://rust-reportcard.xuri.me/report/github.com/tamada/totebag)
Expand Down Expand Up @@ -58,7 +58,7 @@ brew install tamada/tap/totebag
## :whale: Docker
```sh
docker run -it --rm -v $PWD:/workdir ghcr.io/tamada/totebag:0.5.0 [OPTIONS] [ARGUMENTS]...
docker run -it --rm -v $PWD:/workdir ghcr.io/tamada/totebag:0.5.2 [OPTIONS] [ARGUMENTS]...
```
- **Working directory**: `/workdir`
Expand Down
27 changes: 27 additions & 0 deletions dockers/Dockerfile.bookworm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM rust:1-bookworm AS builder

ARG VERSION=0.4.6
ARG TARGETPLATFORM

WORKDIR /work/totebag

COPY . .
RUN cargo build --release

FROM debian:bookworm-slim

ARG VERSION=0.4.6

LABEL org.opencontainers.image.source=https://github.com/tamada/totebag \
org.opencontainers.image.version=${VERSION} \
org.opencontainers.image.title=totebag \
org.opencontainers.image.description="totebag is a simple file transfer tool."

RUN adduser --disabled-password --disabled-login --home /workdir nonroot \
&& mkdir -p /workdir
COPY --from=builder /work/totebag/target/release/totebag /opt/totebag/totebag

WORKDIR /workdir
USER nonroot

ENTRYPOINT [ "/opt/totebag/totebag" ]
27 changes: 27 additions & 0 deletions dockers/Dockerfile.bullseye
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM rust:1-bullseye AS builder

ARG VERSION=0.4.6
ARG TARGETPLATFORM

WORKDIR /work/totebag

COPY . .
RUN cargo build --release

FROM debian:bullseye-slim

ARG VERSION=0.4.6

LABEL org.opencontainers.image.source=https://github.com/tamada/totebag \
org.opencontainers.image.version=${VERSION} \
org.opencontainers.image.title=totebag \
org.opencontainers.image.description="totebag is a simple file transfer tool."

RUN adduser --disabled-password --disabled-login --home /workdir nonroot \
&& mkdir -p /workdir
COPY --from=builder /work/totebag/target/release/totebag /opt/totebag/totebag

WORKDIR /workdir
USER nonroot

ENTRYPOINT [ "/opt/totebag/totebag" ]
4 changes: 2 additions & 2 deletions dockers/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:3.16 AS builder

ARG VERSION=0.4.6
ARG VERSION=0.5.2
ARG TARGETPLATFORM
ARG PLATFORM=${TARGETPLATFORM#linux/}

Expand All @@ -12,7 +12,7 @@ RUN apk add --no-cache curl tar gzip \

FROM alpine:3.16

ARG VERSION=0.4.6
ARG VERSION=0.5.2

LABEL org.opencontainers.image.source https://github.com/tamada/totebag

Expand Down
22 changes: 0 additions & 22 deletions dockers/distroless/Dockerfile

This file was deleted.

128 changes: 128 additions & 0 deletions slide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
---
title: "totebag -- A tool for archiving files and directories and extracting several archive formats."
author: "Haruaki Tamada"
slide: true
marp: true
theme: default
---

# totebag

## A tool for extracting/archiving files and directories in several formats

![](./docs/assets/logo.jpeg)

Haruaki Tamada (@tamada)
https://github.com/tamada/totebag

---

# Why totebag?

- 世の中には多くの圧縮,解凍ツールがある.
- しかし,それらを扱うツールの利用方法は統一されていない.
- 各ツールの使い方をいちいち調べるのが面倒だ!
- 一つのツールで,複数の圧縮形式を扱おう!
- 最近の言語は,ライブラリが充実しているのでできるはず!

---

# 作ってみた.

- **ツール名**  totebag
- **言語**    Rust
- **ロゴ作成**  Microsoft image creator(AI)
- **タグライン**
- A tool for archiving files and directories and extracting several archive formats

---

# サポートしている圧縮形式

- Lha/Lzh(解凍のみ)
- Rar(解凍のみ)
- 7Zip
- Tar(tar, tar+gz, tar+xz, tar+bz2)
- Zip(zip, jar, war, ear)

---

# Usage

```sh
A tool for extracting/archiving files and directories in multiple formats.

Usage: totebag [OPTIONS] [ARGUMENTS]...

Arguments:
[ARGUMENTS]... List of files or directories to be processed.

Options:
-m, --mode <MODE> Mode of operation. [default: auto]
[possible values: auto, archive, extract, list]
-o, --output <DEST> Output file in archive mode, or output directory
in extraction mode
--to-archive-name-dir extract files to DEST/ARCHIVE_NAME directory
(extract mode).
-n, --no-recursive No recursive directory (archive mode).
-v, --verbose Display verbose output.
--overwrite Overwrite existing files.
-h, --help Print help
-V, --version Print version
```
---
# 処理内容
- 解凍
- コマンドライン引数全てが圧縮ファイルだと解凍モードになる.
- リスト
- `mode``list` を指定すると,アーカイブ内のファイル一覧を表示する.
- 圧縮
- `mode``auto` で,コマンドライン引数に圧縮ファイル以外が指定されていると圧縮モードになる.
---
# Rust
- コンパイルがものすごく面倒.
- コンパイルが通るとメモリ関連の実行時エラーがほぼ起こらない.
- だから良い,という意見もわかるし,慣れてくると楽になる.
- けれど,実装に取り掛かるのにものすごく気合がいる言語だなぁ.
---
# Cargo
- :+1: 言語標準!
- :+1: パッケージマネージャ機能が付いている.
- :+1: 様々な拡張機能が導入可能.
- :-1: 拡張機能の導入に準備が必要.
- :-1: 外部コマンドを実行できない.
- 短気(プログラマの三大美徳の一つ)が満たされない.
- 新たに導入しようとするときに,準備のコマンドを何度も入力しないといけない.
- 環境によって動作する/しないが異なってくる.
---
# 学んだこと
- Rust
- ある程度思い通りにプログラムを組めるようになった.
- 2年前に学習したときは,非常に苦労した上に,思い通りにならないことが多かった.
- Marp
- いつまでもスライド作りを PowerPoint に頼るのは嫌.
- テキスト形式でスライドを作りたい.
- 授業資料,論文,プログラムなどほぼ全ての成果物をGitHubで管理しているため.
- レイアウトが思い通りにならない...
- 後から pptx を編集できない...
---
# まとめ
- 複数の圧縮形式を取り扱うツール totebag を作成した.
- Rust で作成した.
- Rust の学習につながった.
- Marp を使い続けるのは様子見かな???
21 changes: 18 additions & 3 deletions src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ impl ExtractorOpts {

/// Returns the base of the destination directory for the archive file.
/// The target is the archive file name of source.
pub fn destination(&self, target: &PathBuf) -> PathBuf {
pub fn destination(&self, target: &PathBuf) -> Result<PathBuf> {
let dest = self.destination_file(target);
println!("destination: {:?}", dest);
if dest.exists() && !self.overwrite {
Err(ToteError::FileExists(dest.clone()))
} else {
Ok(dest)
}
}

fn destination_file(&self, target: &PathBuf) -> PathBuf {
if self.use_archive_name_dir {
let file_name = target.file_name().unwrap().to_str().unwrap();
let ext = target.extension().unwrap().to_str().unwrap();
Expand Down Expand Up @@ -102,7 +112,10 @@ mod tests {
v: create_verboser(false),
};
let target = PathBuf::from("/tmp/archive.zip");
assert_eq!(opts1.destination(&target), PathBuf::from("./archive"));

if let Ok(t) = opts1.destination(&target) {
assert_eq!(t, PathBuf::from("./archive"));
}

let opts2 = ExtractorOpts {
dest: PathBuf::from("."),
Expand All @@ -111,7 +124,9 @@ mod tests {
v: create_verboser(false),
};
let target = PathBuf::from("/tmp/archive.zip");
assert_eq!(opts2.destination(&target), PathBuf::from("."));
if let Ok(t) = opts2.destination(&target) {
assert_eq!(t, PathBuf::from("."));
}
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/extractor/lha.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl Extractor for LhaExtractor {
loop {
let header = reader.header();
let name = header.parse_pathname();
let dest = opts.destination(&archive_file).join(&name);
let dest = opts.destination(&archive_file)?.join(&name);
if reader.is_decoder_supported() {
opts.v.verbose(format!(
"extracting {} ({} bytes)",
Expand Down
2 changes: 1 addition & 1 deletion src/extractor/rar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Extractor for RarExtractor {
let mut file = archive.open_for_processing().unwrap();
while let Some(header) = file.read_header().unwrap() {
let name = header.entry().filename.to_str().unwrap();
let dest = opts.destination(&archive_file).join(PathBuf::from(name));
let dest = opts.destination(&archive_file)?.join(PathBuf::from(name));
file = if header.entry().is_file() {
opts.v.verbose(format!("extracting {} ({} bytes)", name, header.entry().unpacked_size));
create_dir_all(dest.parent().unwrap()).unwrap();
Expand Down
Loading

0 comments on commit 8e34824

Please sign in to comment.