Skip to content

Commit

Permalink
Make --target-path optional for pack/unpack (#186)
Browse files Browse the repository at this point in the history
- **FIXED** `--target-path` for `pack` command is now optional
- **FIXED** `--target-path` for `unpack` command is now optional
  • Loading branch information
DanEngelbrecht authored Dec 4, 2021
1 parent 67d9ea9 commit 7a5bab1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ jobs:
release_name: Release ${{ github.ref }}
body: |
Changes in this Release
- **ADDED** `version` command showing the current executable version
- **ADDED** `pack` command to create a self contained archive from a folder
- **ADDED** `unpack` command to update a folder from a self contained archive
- **UPDATED** Updated longtail to v0.2.7
- **FIXED** `--target-path` for `pack` command is now optional
- **FIXED** `--target-path` for `unpack` command is now optional
draft: false
prerelease: false
- name: Download Linux artifacts
Expand Down
23 changes: 20 additions & 3 deletions commands/cmd_pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package commands

import (
"context"
"fmt"
"strings"
"time"

"github.com/DanEngelbrecht/golongtail/longtaillib"
Expand Down Expand Up @@ -49,6 +51,21 @@ func pack(
return storeStats, timeStats, errors.Wrapf(err, fname)
}

resolvedTargetPath := ""
if targetFilePath == "" {
urlSplit := strings.Split(longtailutils.NormalizePath(sourceFolderPath), "/")
sourceName := urlSplit[len(urlSplit)-1]
sourceNameSplit := strings.Split(sourceName, ".")
resolvedTargetPath = sourceNameSplit[0]
if resolvedTargetPath == "" {
err = fmt.Errorf("Unable to resolve target path using `%s` as base", sourceFolderPath)
return storeStats, timeStats, errors.Wrap(err, fname)
}
resolvedTargetPath += ".la"
} else {
resolvedTargetPath = targetFilePath
}

fs := longtaillib.CreateFSStorageAPI()
defer fs.Dispose()

Expand Down Expand Up @@ -118,9 +135,9 @@ func pack(
createArchiveIndexTime := time.Since(createArchiveIndexStartTime)
timeStats = append(timeStats, longtailutils.TimeStat{"Create archive index", createArchiveIndexTime})

archiveIndexBlockStore := longtaillib.CreateArchiveBlockStoreAPI(fs, targetFilePath, archiveIndex, true)
archiveIndexBlockStore := longtaillib.CreateArchiveBlockStoreAPI(fs, resolvedTargetPath, archiveIndex, true)
if !archiveIndexBlockStore.IsValid() {
err = errors.Wrapf(err, "Failed creating archive store for `%s`", targetFilePath)
err = errors.Wrapf(err, "Failed creating archive store for `%s`", resolvedTargetPath)
return storeStats, timeStats, errors.Wrapf(err, fname)
}
defer archiveIndexBlockStore.Dispose()
Expand Down Expand Up @@ -175,7 +192,7 @@ func pack(
type PackCmd struct {
SourcePath string `name:"source-path" help:"Source folder path" required:""`
SourceIndexPath string `name:"source-index-path" help:"Optional pre-computed index of source-path"`
TargetPath string `name:"target-path" help:"Target file uri" required:""`
TargetPath string `name:"target-path" help:"Target file uri"`
TargetChunkSizeOption
MaxChunksPerBlockOption
TargetBlockSizeOption
Expand Down
2 changes: 1 addition & 1 deletion commands/cmd_unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func unpack(

type UnpackCmd struct {
SourcePath string `name:"source-path" help:"Source folder path" required:""`
TargetPath string `name:"target-path" help:"Target file uri" required:""`
TargetPath string `name:"target-path" help:"Target file uri"`
TargetIndexPath string `name:"target-index-path" help:"Optional pre-computed index of target-path"`
RetainPermissionsOption
ValidateTargetOption
Expand Down

0 comments on commit 7a5bab1

Please sign in to comment.