Skip to content

Commit

Permalink
Use the old session file's creation time when backing up a session
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertAudi committed Mar 31, 2019
1 parent 03f9e10 commit ca0c529
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/commands/backup.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@ function __tsm::commands::backup::session() {
return 1
fi

local session_dump
session_dump="$(__tsm::helpers::dump)" || return $status

local filename="$(__tsm::utils::filename).$(__tsm::utils::random).txt"
[[ -n "$session_file" ]] && filename="${session_file:A:t:r}.${filename}"

builtin print -- "$session_dump" > "${TSM_BACKUPS_DIR}/$filename" \
local filename="${session_file:A:t:r}.$(__tsm::utils::datetime::ctime "$session_file").$(__tsm::utils::random).txt"
command cp -f "$session_file" "${TSM_BACKUPS_DIR}/$filename" >/dev/null \
&& __tsm::commands::backup::clean
}

Expand Down
1 change: 1 addition & 0 deletions src/setup.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ emulate -LR zsh

zmodload zsh/parameter
zmodload zsh/datetime
zmodload -F zsh/stat b:zstat

setopt extended_glob
setopt typeset_silent
Expand Down
5 changes: 5 additions & 0 deletions src/utils/datetime.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ function __tsm::utils::datetime() {
# then it's definitely not mine. Don't be a PITA.
builtin printf "%s.%03d" "$(builtin strftime "%Y-%m-%dT%H:%M:%S" $epochtime[1])" "$(($epochtime[2] / 1000000))"
}

# Return the creation time of a file
function __tsm::utils::datetime::ctime() {
builtin zstat -F "%Y-%m-%dT%H:%M:%S" +ctime "$1"
}

0 comments on commit ca0c529

Please sign in to comment.