Documentation ¶
Overview ¶
Copyright (c) 2020 tickstep.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2020 tickstep.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2020 tickstep.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright (c) 2020 tickstep.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func CleanPath(p string) string
- func GetSuffixPath(fullFilePath, rootFilePath string) string
- func WalkAllFile(file SymlinkFile, walkFn MyWalkFunc) error
- type ChecksumWriteUnit
- type ChecksumWriter
- type LocalFileEntity
- type LocalFileMeta
- type MyWalkFunc
- type SymlinkFile
- func NewSymlinkFile(filePath string) SymlinkFile
- func RetrieveRealPath(file SymlinkFile) (SymlinkFile, os.FileInfo, error)
- func RetrieveRealPathFromLogicPath(logicFilePath string) (SymlinkFile, os.FileInfo, error)
- func RetrieveRealPathFromLogicSuffixPath(rootFile SymlinkFile, logicSuffixPath string) (SymlinkFile, os.FileInfo, error)
Constants ¶
const ( // CHECKSUM_MD5 获取文件的 md5 值 CHECKSUM_MD5 int = 1 << iota // CHECKSUM_CRC32 获取文件的 crc32 值 CHECKSUM_CRC32 // CHECKSUM_SHA1 获取文件的 sha1 值 CHECKSUM_SHA1 )
const ( // DefaultBufSize 默认的bufSize DefaultBufSize = int(256 * converter.KB) )
Variables ¶
Functions ¶
func GetSuffixPath ¶ added in v0.1.8
GetSuffixPath 获取相对路径。即fullFilePath相对rootFilePath的相对路径
func WalkAllFile ¶ added in v0.1.8
func WalkAllFile(file SymlinkFile, walkFn MyWalkFunc) error
WalkAllFile 遍历本地文件,支持软链接(符号逻辑)文件(Linux & Windows & macOS)
Types ¶
type ChecksumWriteUnit ¶
type ChecksumWriteUnit struct { SliceEnd int64 End int64 SliceSum interface{} Sum interface{} OnlySliceSum bool ChecksumWriter ChecksumWriter // contains filtered or unexported fields }
type ChecksumWriter ¶
func NewHash32ChecksumWriter ¶
func NewHash32ChecksumWriter(h32 hash.Hash32) ChecksumWriter
func NewHashChecksumWriter ¶
func NewHashChecksumWriter(h hash.Hash) ChecksumWriter
type LocalFileEntity ¶
type LocalFileEntity struct { LocalFileMeta // contains filtered or unexported fields }
LocalFileEntity 校验本地文件
func GetFileSum ¶
func GetFileSum(localPath string, flag int) (lfc *LocalFileEntity, err error)
GetFileSum 获取文件的大小, md5, crc32
func NewLocalFileEntity ¶
func NewLocalFileEntity(localPath string) *LocalFileEntity
func NewLocalFileEntityWithBufSize ¶
func NewLocalFileEntityWithBufSize(file SymlinkFile, bufSize int) *LocalFileEntity
func NewLocalSymlinkFileEntity ¶ added in v0.1.8
func NewLocalSymlinkFileEntity(file SymlinkFile) *LocalFileEntity
func (*LocalFileEntity) OpenPath ¶
func (lfc *LocalFileEntity) OpenPath() error
OpenPath 检查文件状态并获取文件的大小 (Length)
func (*LocalFileEntity) Sum ¶
func (lfc *LocalFileEntity) Sum(checkSumFlag int) (err error)
Sum 计算文件摘要值
type LocalFileMeta ¶
type LocalFileMeta struct { Path SymlinkFile `json:"path,omitempty"` // 本地路径 Length int64 `json:"length,omitempty"` // 文件大小 MD5 string `json:"md5,omitempty"` // 文件的 md5 CRC32 uint32 `json:"crc32,omitempty"` // 文件的 crc32 SHA1 string `json:"sha1,omitempty"` // 文件的 sha1 ModTime int64 `json:"modtime"` // 修改日期 // 网盘上传参数 UploadOpEntity *aliyunpan.CreateFileUploadResult `json:"uploadOpEntity"` // ParentFolderId 存储云盘的目录ID ParentFolderId string `json:"parent_folder_id,omitempty"` }
LocalFileMeta 本地文件元信息
func (*LocalFileMeta) CompleteAbsPath ¶
func (lfm *LocalFileMeta) CompleteAbsPath()
CompleteAbsPath 补齐绝对路径
func (*LocalFileMeta) EqualLengthMD5 ¶
func (lfm *LocalFileMeta) EqualLengthMD5(m *LocalFileMeta) bool
EqualLengthMD5 检测md5和大小是否相同
func (*LocalFileMeta) EqualLengthSHA1 ¶
func (lfm *LocalFileMeta) EqualLengthSHA1(m *LocalFileMeta) bool
EqualLengthSHA1 检测sha1和大小是否相同
type MyWalkFunc ¶ added in v0.1.8
type MyWalkFunc func(path SymlinkFile, info fs.FileInfo, err error) error
type SymlinkFile ¶ added in v0.1.8
type SymlinkFile struct { // LogicPath 逻辑路径 LogicPath string `json:"logicPath"` // RealPath 真正的文件路径,即文件的本体 RealPath string `json:"realPath"` }
SymlinkFile 软链接文件,Linux/macOS的ln,Windows的mklink命令创建的文件链接。对于非软链接文件而言,真实的路径和逻辑路径是一样的。
func NewSymlinkFile ¶ added in v0.1.8
func NewSymlinkFile(filePath string) SymlinkFile
func RetrieveRealPath ¶ added in v0.1.8
func RetrieveRealPath(file SymlinkFile) (SymlinkFile, os.FileInfo, error)
RetrieveRealPath 递归调用找到软链接文件的真实文件对应的路径信息
func RetrieveRealPathFromLogicPath ¶ added in v0.1.8
func RetrieveRealPathFromLogicPath(logicFilePath string) (SymlinkFile, os.FileInfo, error)
RetrieveRealPathFromLogicPath 遍历路径获取逻辑路径真正的文件路径。如果逻辑路径不完全存在,则返回已经存在的那部分路径
logicFilePath - 目标逻辑路径 由于目标逻辑路径期间有可能会经过多次符号逻辑文件,同时有部分逻辑路径可能是不存在的,所以需要按照逻辑文件起始开始进行遍历,直至完成逻辑文件路径的所有遍历, 或者直到不存在的逻辑文件部分,然后返回。
例如逻辑文件路径:/Volumes/Downloads/dev/sync_drive_config.json。
如果/Volumes/Downloads存在而后面部分不存在,则最终结果返回/Volumes/Downloads对应的文件信息,同时返回error
func RetrieveRealPathFromLogicSuffixPath ¶ added in v0.1.8
func RetrieveRealPathFromLogicSuffixPath(rootFile SymlinkFile, logicSuffixPath string) (SymlinkFile, os.FileInfo, error)
RetrieveRealPathFromLogicSuffixPath 通过指定根目录和后缀逻辑路径,获取文件对应的真实路径信息
整体功能和 RetrieveRealPathFromLogicPath 一致,将逻辑路径分成根路径和后缀路径两部分,并且根路径必须存在。
func (*SymlinkFile) String ¶ added in v0.1.8
func (s *SymlinkFile) String() string