8000 wal-g/walk.go at master · cuulee/wal-g · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
{"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":"cmd","path":"cmd","contentType":"directory"},{"name":"test_tools","path":"test_tools","contentType":"directory"},{"name":"vendor","path":"vendor","contentType":"directory"},{"name":".travis.yml","path":".travis.yml","contentType":"file"},{"name":"CONTRIBUTORS","path":"CONTRIBUTORS","contentType":"file"},{"name":"LICENSE.md","path":"LICENSE.md","contentType":"file"},{"name":"Makefile","path":"Makefile","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"backup.go","path":"backup.go","contentType":"file"},{"name":"backup_test.go","path":"backup_test.go","contentType":"file"},{"name":"compress.go","path":"compress.go","contentType":"file"},{"name":"compress_test.go","path":"compress_test.go","contentType":"file"},{"name":"connect.go","path":"connect.go","contentType":"file"},{"name":"connect_test.go","path":"connect_test.go","contentType":"file"},{"name":"decompress.go","path":"decompress.go","contentType":"file"},{"name":"decompress_test.go","path":"decompress_test.go","contentType":"file"},{"name":"error.go","path":"error.go","contentType":"file"},{"name":"extract.go","path":"extract.go","contentType":"file"},{"name":"extract_test.go","path":"extract_test.go","contentType":"file"},{"name":"make.go","path":"make.go","contentType":"file"},{"name":"structs.go","path":"structs.go","contentType":"file"},{"name":"structs_test.go","path":"structs_test.go","contentType":"file"},{"name":"tar.go","path":"tar.go","contentType":"file"},{"name":"timer.go","path":"timer.go","contentType":"file"},{"name":"upload.go","path":"upload.go","contentType":"file"},{"name":"upload_test.go","path":"upload_test.go","contentType":"file"},{"name":"utility.go","path":"utility.go","contentType":"file"},{"name":"utility_test.go","path":"utility_test.go","contentType":"file"},{"name":"walk.go","path":"walk.go","contentType":"file"},{"name":"walk_test.go","path":"walk_test.go","contentType":"file"}],"totalCount":30}},"fileTreeProcessingTime":9.180219999999998,"foldersToFetch":[],"incompleteFileTree":false,"repo":{"id":100831246,"defaultBranch":"master","name":"wal-g","ownerLogin":"cuulee","currentUserCanPush":false,"isFork":true,"isEmpty":false,"createdAt":"2017-08-20T01:32:27.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/1776179?v=4","public":true,"private":false,"isOrgOwned":false},"codeLineWrapEnabled":false,"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"master","listCacheKey":"v0:1621976322.6996129","canEdit":false,"refType":"branch","currentOid":"a2f3a7038eb547712b1dd83e941d795af0aab5b6"},"path":"walk.go","currentUser":null,"blob":{"rawLines":["package walg","","import (","\t\"archive/tar\"","\t\"fmt\"","\t\"github.com/pkg/errors\"","\t\"io\"","\t\"os\"","\t\"path/filepath\"","\t\"strings\"",")","","// ZeroReader generates a slice of zeroes. Used to pad","// tar in cases where length of file changes.","type ZeroReader struct{}","","func (z *ZeroReader) Read(p []byte) (int, error) {","\tzeroes := make([]byte, len(p))","\tn := copy(p, zeroes)","\treturn n, nil","","}","","// TarWalker walks files provided by the passed in directory","// and creates compressed tar members labeled as `part_00i.tar.lzo`.","//","// To see which files and directories are skipped, please consult","// 'structs.go'. Excluded directories will be created but their","// contents will not be included in the tar bundle.","func (bundle *Bundle) TarWalker(path string, info os.FileInfo, err error) error {","\tif err != nil {","\t\treturn errors.Wrap(err, \"TarWalker: walk failed\")","\t}","","\tif info.Name() == \"pg_control\" {","\t\tbundle.Sen = \u0026Sentinel{info, path}","\t} else if bundle.Tb.Size() \u003c= bundle.MinSize {","\t\terr = HandleTar(bundle, path, info)","\t\tif err == filepath.SkipDir {","\t\t\treturn err","\t\t}","\t\tif err != nil {","\t\t\treturn errors.Wrap(err, \"TarWalker: handle tar failed\")","\t\t}","\t} else {","\t\toldTB := bundle.Tb","\t\terr := oldTB.CloseTar()","\t\tif err != nil {","\t\t\treturn errors.Wrap(err, \"TarWalker: failed to close tarball\")","\t\t}","","\t\tbundle.NewTarBall()","\t\terr = HandleTar(bundle, path, info)","\t\tif err == filepath.SkipDir {","\t\t\treturn err","\t\t}","\t\tif err != nil {","\t\t\treturn errors.Wrap(err, \"TarWalker: handle tar failed\")","\t\t}","\t}","\treturn nil","}","","// HandleTar creates underlying tar writer and handles one given file.","// Does not follow symlinks. If file is in EXCLUDE, will not be included","// in the final tarball. EXCLUDED directories are created","// but their contents are not written to local disk.","func HandleTar(bundle TarBundle, path string, info os.FileInfo) error {","\ttarBall := bundle.GetTarBall()","\tfileName := info.Name()","\t_, ok := EXCLUDE[info.Name()]","\ttarBall.SetUp()","\ttarWriter := tarBall.Tw()","","\tif !ok {","\t\thdr, err := tar.FileInfoHeader(info, fileName)","\t\tif err != nil {","\t\t\treturn errors.Wrap(err, \"HandleTar: could not grab header info\")","\t\t}","","\t\thdr.Name = strings.TrimPrefix(path, tarBall.Trim())","\t\tfmt.Println(hdr.Name)","","\t\terr = tarWriter.WriteHeader(hdr)","\t\tif err != nil {","\t\t\treturn errors.Wrap(err, \"HandleTar: failed to write header\")","\t\t}","\t\tif info.Mode().IsRegular() {","\t\t\tf, err := os.Open(path)","\t\t\tif err != nil {","\t\t\t\treturn errors.Wrapf(err, \"HandleTar: failed to open file '%s'\\n\", path)","\t\t\t}","\t\t\tlim := \u0026io.LimitedReader{","\t\t\t\tR: io.MultiReader(f, \u0026ZeroReader{}),","\t\t\t\tN: int64(hdr.Size),","\t\t\t}","","\t\t\t_, err = io.Copy(tarWriter, lim)","\t\t\tif err != nil {","\t\t\t\treturn errors.Wrap(err, \"HandleTar: copy failed\")","\t\t\t}","","\t\t\ttarBall.SetSize(hdr.Size)","\t\t\tf.Close()","\t\t}","\t} else if ok \u0026\u0026 info.Mode().IsDir() {","\t\thdr, err := tar.FileInfoHeader(info, fileName)","\t\tif err != nil {","\t\t\treturn errors.Wrap(err, \"HandleTar: failed to grab header info\")","\t\t}","","\t\thdr.Name = strings.TrimPrefix(path, tarBall.Trim())","\t\tfmt.Println(hdr.Name)","","\t\terr = tarWriter.WriteHeader(hdr)","\t\tif err != nil {","\t\t\treturn errors.Wrap(err, \"HandleTar: failed to write header\")","\t\t}","\t\treturn filepath.SkipDir","\t}","","\treturn nil","}"],"stylingDirectives":null,"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/cuulee/wal-g/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"walk.go","displayUrl":"https://github.com/cuulee/wal-g/blob/master/walk.go?raw=true","headerInfo":{"blobSize":"3.05 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":"https://desktop.github.com","isGitLfs":false,"onBranch":true,"shortPath":"bafa4dc","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Fcuulee%2Fwal-g%2Fblob%2Fmaster%2Fwalk.go","isCSV":false,"isRichtext":false,"toc":null,"lineInfo":{"truncatedLoc":"123","truncatedSloc":"107"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"Go","languageID":132,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/cuulee/wal-g/blob/master/walk.go","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/cuulee/wal-g/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/cuulee/wal-g/raw/refs/heads/master/walk.go","renderImageOrRaw":false,"richText":null,"renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":8,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":null,"showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":null},"copilotInfo":null,"copilotAccessAllowed":false,"modelsAccessAllowed":false,"modelsRepoIntegrationEnabled":false,"csrf_tokens":{"/cuulee/wal-g/branches":{"post":"K4rBMAKLPsHWMujI1n84OdDmDcc_IAZPhRJI-52wgrlp9BAek-ICw3kRqJJUvQ-64ghXR_jd5-_XropH1_GSNw"},"/repos/preferences":{"post":"aMHYZLcDz5zc80CE4OZKyjUatDf4QOv-hc7jmtGVN3fO_ieYdI9F4MlEK38W-PCAMEHg6UTlOvkfQvyK9h293Q"}}},"title":"wal-g/walk.go at master · cuulee/wal-g","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-263cab1760dd.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-98e6e9db3609.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true}}}
0