Skip to content

Commit 1160979

Browse files
committed
select unique filename if default already exists
1 parent 23a3062 commit 1160979

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

git-recover

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,28 @@ function write_one_file {
126126
echo "$OUTPUT_NAME."
127127
}
128128

129+
function unique_filename {
130+
if [ ! -f "${BLOB}" ]; then
131+
echo "$BLOB"
132+
else
133+
cnt=1
134+
while true
135+
do
136+
fn="${BLOB}~${cnt}"
137+
if [ ! -f "${fn}" ]; then
138+
echo "${fn}"
139+
break
140+
fi
141+
cnt=$((cnt+1))
142+
done
143+
fi
144+
}
145+
129146
function write_recoverable {
130147
for i in "${!BLOBS[@]}"; do
131148
BLOB=${BLOBS[$i]}
132149
FILTER_NAME=${FILENAMES[$i]}
133-
OUTPUT_NAME=${FILENAMES[$i]:-$BLOB}
150+
OUTPUT_NAME=${FILENAMES[$i]:-$(unique_filename)}
134151

135152
write_one_file "$BLOB" "$FILTER_NAME" "$OUTPUT_NAME"
136153
done
@@ -235,7 +252,7 @@ function interactive {
235252

236253
case "$ans" in
237254
[yY]*)
238-
write_one_file "${BLOB}" "" "${BLOB}"
255+
write_one_file "${BLOB}" "" "$(unique_filename)"
239256
break
240257
;;
241258
[nN]*)

0 commit comments

Comments
 (0)