Skip to content

Commit

Permalink
UNC path may not contain forward slashes (#214)
Browse files Browse the repository at this point in the history
* UNC path may not contain forward slashes
* update changelog
  • Loading branch information
DanEngelbrecht authored Jun 24, 2022
1 parent 8a70395 commit 9e7464c
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 43 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
##
- **FIXED** Full support for windows extended length paths (UNC paths)

## v0.3.5
- **UPDATED** Updated longtail to 0.3.4

## v0.3.4
Expand Down
7 changes: 4 additions & 3 deletions commands/cmd_clonestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/DanEngelbrecht/golongtail/longtaillib"
"github.com/DanEngelbrecht/golongtail/longtailstorelib"
"github.com/DanEngelbrecht/golongtail/longtailutils"
"github.com/DanEngelbrecht/golongtail/remotestore"
"github.com/pkg/errors"
Expand Down Expand Up @@ -291,7 +292,7 @@ func updateCurrentVersionFromLongtail(
localVersionIndex,
sourceVersionIndex,
versionDiff,
longtailutils.NormalizePath(targetPath),
longtailstorelib.NormalizeFileSystemPath(targetPath),
retainPermissions)

localVersionIndex.Dispose()
Expand Down Expand Up @@ -432,7 +433,7 @@ func cloneOneVersion(
&writeContentProgress,
versionMissingStoreIndex,
targetVersionIndex,
longtailutils.NormalizePath(targetPath))
longtailstorelib.NormalizeFileSystemPath(targetPath))
writeContentProgress.Dispose()
if err != nil {
err = errors.Wrap(err, fmt.Sprintf("failed writing content from `%s`", targetPath))
Expand Down Expand Up @@ -558,7 +559,7 @@ func cloneStore(
var sourceCompressBlockStore longtaillib.Longtail_BlockStoreAPI

if len(localCachePath) > 0 {
localIndexStore = longtaillib.CreateFSBlockStore(jobs, localFS, longtailutils.NormalizePath(localCachePath), "", enableFileMapping)
localIndexStore = longtaillib.CreateFSBlockStore(jobs, localFS, longtailstorelib.NormalizeFileSystemPath(localCachePath), "", enableFileMapping)

cacheBlockStore = longtaillib.CreateCacheBlockStore(jobs, localIndexStore, sourceRemoteIndexStore)

Expand Down
3 changes: 2 additions & 1 deletion commands/cmd_clonestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"testing"

"github.com/DanEngelbrecht/golongtail/longtailstorelib"
"github.com/DanEngelbrecht/golongtail/longtailutils"
"github.com/pkg/errors"
)
Expand All @@ -27,7 +28,7 @@ func createZipForFolder(searchPath string) (bytes.Buffer, error) {
return nil
}
subPath := path[len(searchPath)+1:]
fw, err := zw.Create(longtailutils.NormalizePath(subPath))
fw, err := zw.Create(longtailstorelib.NormalizeFileSystemPath(subPath))

if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion commands/cmd_cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/DanEngelbrecht/golongtail/longtaillib"
"github.com/DanEngelbrecht/golongtail/longtailstorelib"
"github.com/DanEngelbrecht/golongtail/longtailutils"
"github.com/DanEngelbrecht/golongtail/remotestore"
"github.com/pkg/errors"
Expand Down Expand Up @@ -63,7 +64,7 @@ func cpVersionIndex(
if localCachePath == "" {
compressBlockStore = longtaillib.CreateCompressBlockStore(remoteIndexStore, creg)
} else {
localIndexStore = longtaillib.CreateFSBlockStore(jobs, localFS, longtailutils.NormalizePath(localCachePath), "", enableFileMapping)
localIndexStore = longtaillib.CreateFSBlockStore(jobs, localFS, longtailstorelib.NormalizeFileSystemPath(localCachePath), "", enableFileMapping)

cacheBlockStore = longtaillib.CreateCacheBlockStore(jobs, localIndexStore, remoteIndexStore)

Expand Down
13 changes: 7 additions & 6 deletions commands/cmd_downsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/DanEngelbrecht/golongtail/longtaillib"
"github.com/DanEngelbrecht/golongtail/longtailstorelib"
"github.com/DanEngelbrecht/golongtail/longtailutils"
"github.com/DanEngelbrecht/golongtail/remotestore"
"github.com/pkg/errors"
Expand Down Expand Up @@ -64,7 +65,7 @@ func downsync(

resolvedTargetFolderPath := ""
if targetFolderPath == "" {
normalizedSourceFilePath := longtailutils.NormalizePath(sourceFilePath)
normalizedSourceFilePath := longtailstorelib.NormalizeFileSystemPath(sourceFilePath)
normalizedSourceFilePath = strings.ReplaceAll(normalizedSourceFilePath, "\\", "/")
urlSplit := strings.Split(normalizedSourceFilePath, "/")
sourceName := urlSplit[len(urlSplit)-1]
Expand All @@ -85,7 +86,7 @@ func downsync(
cacheTargetIndex = false
}

cacheTargetIndexPath := resolvedTargetFolderPath + "/.longtail.index.cache.lvi"
cacheTargetIndexPath := longtailstorelib.NormalizeFileSystemPath(resolvedTargetFolderPath + "/.longtail.index.cache.lvi")

if cacheTargetIndex {
if longtaillib.FileExists(fs, cacheTargetIndexPath) {
Expand Down Expand Up @@ -153,7 +154,7 @@ func downsync(
if localCachePath == "" {
compressBlockStore = longtaillib.CreateCompressBlockStore(remoteIndexStore, creg)
} else {
localIndexStore = longtaillib.CreateFSBlockStore(jobs, localFS, longtailutils.NormalizePath(localCachePath), "", enableFileMapping)
localIndexStore = longtaillib.CreateFSBlockStore(jobs, localFS, longtailstorelib.NormalizeFileSystemPath(localCachePath), "", enableFileMapping)

cacheBlockStore = longtaillib.CreateCacheBlockStore(jobs, localIndexStore, remoteIndexStore)

Expand Down Expand Up @@ -232,7 +233,7 @@ func downsync(
targetVersionIndex,
sourceVersionIndex,
versionDiff,
longtailutils.NormalizePath(resolvedTargetFolderPath),
longtailstorelib.NormalizeFileSystemPath(resolvedTargetFolderPath),
retainPermissions)
if err != nil {
err = errors.Wrapf(err, "Failed writing version `%s` to `%s`", sourceFilePath, targetFolderPath)
Expand Down Expand Up @@ -290,7 +291,7 @@ func downsync(
validateFileInfos, err := longtaillib.GetFilesRecursively(
fs,
pathFilter,
longtailutils.NormalizePath(resolvedTargetFolderPath))
longtailstorelib.NormalizeFileSystemPath(resolvedTargetFolderPath))
if err != nil {
err = errors.Wrapf(err, "Failed to scan `%s`", resolvedTargetFolderPath)
return storeStats, timeStats, errors.Wrap(err, fname)
Expand All @@ -308,7 +309,7 @@ func downsync(
chunker,
jobs,
&createVersionIndexProgress,
longtailutils.NormalizePath(resolvedTargetFolderPath),
longtailstorelib.NormalizeFileSystemPath(resolvedTargetFolderPath),
validateFileInfos,
nil,
targetChunkSize,
Expand Down
5 changes: 3 additions & 2 deletions commands/cmd_pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/DanEngelbrecht/golongtail/longtaillib"
"github.com/DanEngelbrecht/golongtail/longtailstorelib"
"github.com/DanEngelbrecht/golongtail/longtailutils"
"github.com/pkg/errors"

Expand Down Expand Up @@ -55,7 +56,7 @@ func pack(

resolvedTargetPath := ""
if targetFilePath == "" {
urlSplit := strings.Split(longtailutils.NormalizePath(sourceFolderPath), "/")
urlSplit := strings.Split(longtailstorelib.NormalizeFileSystemPath(sourceFolderPath), "/")
sourceName := urlSplit[len(urlSplit)-1]
sourceNameSplit := strings.Split(sourceName, ".")
resolvedTargetPath = sourceNameSplit[0]
Expand Down Expand Up @@ -159,7 +160,7 @@ func pack(
&writeContentProgress,
storeIndex,
vindex,
longtailutils.NormalizePath(sourceFolderPath))
longtailstorelib.NormalizeFileSystemPath(sourceFolderPath))
if err != nil {
err = errors.Wrapf(err, "Failed writing content from `%s`", sourceFolderPath)
return storeStats, timeStats, errors.Wrapf(err, fname)
Expand Down
3 changes: 2 additions & 1 deletion commands/cmd_printVersionUsage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/DanEngelbrecht/golongtail/longtaillib"
"github.com/DanEngelbrecht/golongtail/longtailstorelib"
"github.com/DanEngelbrecht/golongtail/longtailutils"
"github.com/DanEngelbrecht/golongtail/remotestore"
"github.com/pkg/errors"
Expand Down Expand Up @@ -55,7 +56,7 @@ func printVersionUsage(
indexStore = remoteIndexStore
} else {
localFS = longtaillib.CreateFSStorageAPI()
localIndexStore = longtaillib.CreateFSBlockStore(jobs, localFS, longtailutils.NormalizePath(localCachePath), "", false)
localIndexStore = longtaillib.CreateFSBlockStore(jobs, localFS, longtailstorelib.NormalizeFileSystemPath(localCachePath), "", false)

cacheBlockStore = longtaillib.CreateCacheBlockStore(jobs, localIndexStore, remoteIndexStore)

Expand Down
11 changes: 6 additions & 5 deletions commands/cmd_unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/DanEngelbrecht/golongtail/longtaillib"
"github.com/DanEngelbrecht/golongtail/longtailstorelib"
"github.com/DanEngelbrecht/golongtail/longtailutils"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -56,7 +57,7 @@ func unpack(

resolvedTargetFolderPath := ""
if targetFolderPath == "" {
urlSplit := strings.Split(longtailutils.NormalizePath(sourceFilePath), "/")
urlSplit := strings.Split(longtailstorelib.NormalizeFileSystemPath(sourceFilePath), "/")
sourceName := urlSplit[len(urlSplit)-1]
sourceNameSplit := strings.Split(sourceName, ".")
resolvedTargetFolderPath = sourceNameSplit[0]
Expand All @@ -75,7 +76,7 @@ func unpack(
cacheTargetIndex = false
}

cacheTargetIndexPath := resolvedTargetFolderPath + "/.longtail.index.cache.lvi"
cacheTargetIndexPath := longtailstorelib.NormalizeFileSystemPath(resolvedTargetFolderPath + "/.longtail.index.cache.lvi")

if cacheTargetIndex {
if longtaillib.FileExists(fs, cacheTargetIndexPath) {
Expand Down Expand Up @@ -204,7 +205,7 @@ func unpack(
targetVersionIndex,
sourceVersionIndex,
versionDiff,
longtailutils.NormalizePath(resolvedTargetFolderPath),
longtailstorelib.NormalizeFileSystemPath(resolvedTargetFolderPath),
retainPermissions)
if err != nil {
err = errors.Wrapf(err, "Failed writing version `%s` to `%s`", sourceFilePath, targetFolderPath)
Expand Down Expand Up @@ -252,7 +253,7 @@ func unpack(
validateFileInfos, err := longtaillib.GetFilesRecursively(
fs,
pathFilter,
longtailutils.NormalizePath(resolvedTargetFolderPath))
longtailstorelib.NormalizeFileSystemPath(resolvedTargetFolderPath))
if err != nil {
err = errors.Wrapf(err, "Failed to scan `%s`", resolvedTargetFolderPath)
return storeStats, timeStats, errors.Wrap(err, fname)
Expand All @@ -270,7 +271,7 @@ func unpack(
chunker,
jobs,
&createVersionIndexProgress,
longtailutils.NormalizePath(resolvedTargetFolderPath),
longtailstorelib.NormalizeFileSystemPath(resolvedTargetFolderPath),
validateFileInfos,
nil,
targetChunkSize,
Expand Down
3 changes: 2 additions & 1 deletion commands/cmd_upsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/DanEngelbrecht/golongtail/longtaillib"
"github.com/DanEngelbrecht/golongtail/longtailstorelib"
"github.com/DanEngelbrecht/golongtail/longtailutils"
"github.com/DanEngelbrecht/golongtail/remotestore"
"github.com/pkg/errors"
Expand Down Expand Up @@ -151,7 +152,7 @@ func upsync(
&writeContentProgress,
versionMissingStoreIndex,
vindex,
longtailutils.NormalizePath(sourceFolderPath))
longtailstorelib.NormalizeFileSystemPath(sourceFolderPath))
if err != nil {
err = errors.Wrapf(err, "Failed writing content from `%s`", sourceFolderPath)
return storeStats, timeStats, errors.Wrapf(err, fname)
Expand Down
4 changes: 4 additions & 0 deletions longtailstorelib/blobStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func CreateBlobStoreForURI(uri string, opts ...BlobStoreOption) (BlobStore, erro
if strings.HasPrefix(uri, "fsblob://") {
return NewFSBlobStore(uri[len("fsblob://"):], false)
}
// Special case for unc paths
if strings.HasPrefix(uri, UNCPrefix) {
return NewFSBlobStore(uri, false)
}
blobStoreURL, err := url.Parse(uri)
if err == nil {
switch blobStoreURL.Scheme {
Expand Down
20 changes: 13 additions & 7 deletions longtailstorelib/fsstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ type fsBlobObject struct {
metageneration int64
}

func normalizePath(path string) string {
doubleForwardRemoved := strings.Replace(path, "//", "/", -1)
doubleBackwardRemoved := strings.Replace(doubleForwardRemoved, "\\\\", "/", -1)
backwardRemoved := strings.Replace(doubleBackwardRemoved, "\\", "/", -1)
return backwardRemoved
const UNCPrefix = "\\\\?\\"

func NormalizeFileSystemPath(path string) string {
if strings.HasPrefix(path, UNCPrefix) {
forwardSlashReplaced := strings.Replace(path, "/", "\\", -1)
doubleBackwardRemoved := UNCPrefix + strings.Replace(forwardSlashReplaced[len(UNCPrefix):], "\\\\", "\\", -1)
return doubleBackwardRemoved
}
backwardRemoved := strings.Replace(path, "\\", "/", -1)
doubleForwardRemoved := strings.Replace(backwardRemoved, "//", "/", -1)
return doubleForwardRemoved
}

// NewFSBlobStore ...
Expand All @@ -52,7 +58,7 @@ func (blobStore *fsBlobStore) String() string {
}

func (blobClient *fsBlobClient) NewObject(filepath string) (BlobObject, error) {
fsPath := path.Join(blobClient.store.prefix, filepath)
fsPath := NormalizeFileSystemPath(path.Join(blobClient.store.prefix, filepath))
return &fsBlobObject{client: blobClient, path: fsPath, metageneration: -1}, nil
}

Expand All @@ -71,7 +77,7 @@ func (blobClient *fsBlobClient) GetObjects(pathPrefix string) ([]BlobProperties,
if strings.HasSuffix(path, "._lck") {
return nil
}
leafPath := normalizePath(path[len(searchPath)+1:])
leafPath := NormalizeFileSystemPath(path[len(searchPath)+1:])
if len(leafPath) < len(pathPrefix) {
return nil
}
Expand Down
5 changes: 3 additions & 2 deletions longtailutils/folderscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/DanEngelbrecht/golongtail/longtaillib"
"github.com/DanEngelbrecht/golongtail/longtailstorelib"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
Expand All @@ -29,7 +30,7 @@ func (scanner *AsyncFolderScanner) Scan(
fileInfos, err := longtaillib.GetFilesRecursively(
fs,
pathFilter,
NormalizePath(sourceFolderPath))
longtailstorelib.NormalizeFileSystemPath(sourceFolderPath))
if err != nil {
err := errors.Wrap(err, fmt.Sprintf("Failed getting folder structure for `%s`", sourceFolderPath))
scanner.err = errors.Wrap(err, fname)
Expand Down Expand Up @@ -95,7 +96,7 @@ func GetFolderIndex(
chunker,
jobs,
&createVersionIndexProgress,
NormalizePath(sourceFolderPath),
longtailstorelib.NormalizeFileSystemPath(sourceFolderPath),
fileInfos,
compressionTypes,
targetChunkSize,
Expand Down
13 changes: 0 additions & 13 deletions longtailutils/pathfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,13 @@ package longtailutils
import (
"context"
"regexp"
"strings"

"github.com/DanEngelbrecht/golongtail/longtaillib"
"github.com/pkg/errors"

log "github.com/sirupsen/logrus"
)

const uncprefix = "\\\\?\\"

func NormalizePath(path string) string {
doubleForwardRemoved := strings.Replace(path, "//", "/", -1)
if strings.HasPrefix(doubleForwardRemoved, uncprefix) {
doubleBackwardRemoved := uncprefix + strings.Replace(doubleForwardRemoved[4:], "\\\\", "\\", -1)
return doubleBackwardRemoved
}
doubleBackwardRemoved := strings.Replace(doubleForwardRemoved, "\\\\", "/", -1)
return doubleBackwardRemoved
}

type regexPathFilter struct {
compiledIncludeRegexes []*regexp.Regexp
compiledExcludeRegexes []*regexp.Regexp
Expand Down
2 changes: 1 addition & 1 deletion remotestore/remotestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ func getStoreIndexFromBlocks(
}

blockPath := getBlockPath("chunks", blockIndex.GetBlockHash())
if blockPath == longtailutils.NormalizePath(blockKey) {
if blockPath == longtailstorelib.NormalizeFileSystemPath(blockKey) {
batchBlockIndexes[batchPos] = blockIndex
} else {
log.Warnf("Block %s name does not match content hash, expected name %s", blockKey, blockPath)
Expand Down

0 comments on commit 9e7464c

Please sign in to comment.