Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cmd/slackdump/internal/diag/edge.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ func save(filename string, r any) error {
if err != nil {
return err
}
defer f.Close()
enc := json.NewEncoder(f)
enc.SetIndent("", " ")
enc.Encode(r)
return err
if err := enc.Encode(r); err != nil {
_ = f.Close()
return err
}
return f.Close()
}
31 changes: 23 additions & 8 deletions cmd/slackdump/internal/diag/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,30 +153,45 @@ func runEncrypt(ctx context.Context, cmd *base.Command, args []string) error {
if err != nil {
return err
}
defer in.Close()
defer out.Close()
defer func() { _ = in.Close() }()

var w io.Writer = out
var aw io.WriteCloser
if arm || gArm {
// arm if requested
aw, err := armor.Encode(out, "PGP MESSAGE", nil)
aw, err = armor.Encode(out, "PGP MESSAGE", nil)
if err != nil {
_ = out.Close()
base.SetExitStatus(base.SApplicationError)
return err
}
defer aw.Close()
w = aw
}

cw, err := openpgp.Encrypt(w, []*openpgp.Entity{recipient}, nil, &openpgp.FileHints{IsBinary: true}, nil)
if err != nil {
if aw != nil {
_ = aw.Close()
}
_ = out.Close()
base.SetExitStatus(base.SApplicationError)
return err
}
defer cw.Close()
if _, err := io.Copy(cw, in); err != nil {
_, copyErr := io.Copy(cw, in)
if err := cw.Close(); err != nil && copyErr == nil {
copyErr = err
}
if aw != nil {
if err := aw.Close(); err != nil && copyErr == nil {
copyErr = err
}
}
if err := out.Close(); err != nil && copyErr == nil {
copyErr = err
}
if copyErr != nil {
base.SetExitStatus(base.SApplicationError)
return err
return copyErr
}
return nil
}
Expand Down Expand Up @@ -212,7 +227,7 @@ func parseArgs(args []string) (in io.ReadCloser, out io.WriteCloser, arm bool, e
} else {
out, err = os.Create(args[1])
if err != nil {
in.Close()
_ = in.Close()
base.SetExitStatus(base.SApplicationError)
return nil, nil, false, err
}
Expand Down
18 changes: 14 additions & 4 deletions cmd/slackdump/internal/diag/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,11 @@ func mergeSource(ctx context.Context, target mergeTarget, conn *sqlx.DB, src sou
if err != nil {
return fmt.Errorf("creating session: %w", err)
}
defer dbp.Abort()
defer func() {
if err := dbp.Abort(); err != nil {
slog.WarnContext(ctx, "aborting merge session", "error", err)
}
}()

// Workspace info
if wsi, err := src.WorkspaceInfo(ctx); err == nil {
Expand Down Expand Up @@ -467,15 +471,21 @@ func copyAvatars(ctx context.Context, avst source.Storage, users []slack.User, t
}
dstFile, err := trgFSA.Create(dstLoc)
if err != nil {
srcFile.Close()
if err := srcFile.Close(); err != nil {
slog.WarnContext(ctx, "closing avatar source", "user", u.ID, "error", err)
}
slog.WarnContext(ctx, "creating avatar destination", "user", u.ID, "error", err)
continue
}
if _, err := io.Copy(dstFile, srcFile); err != nil {
slog.WarnContext(ctx, "copying avatar", "user", u.ID, "error", err)
}
srcFile.Close()
dstFile.Close()
if err := srcFile.Close(); err != nil {
slog.WarnContext(ctx, "closing avatar source", "user", u.ID, "error", err)
}
if err := dstFile.Close(); err != nil {
slog.WarnContext(ctx, "closing avatar destination", "user", u.ID, "error", err)
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions cmd/slackdump/internal/diag/rawoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,19 @@ func saveOutput(ctx context.Context, cl *http.Client, filename string, token str
if err != nil {
return err
}
defer w.Close()

log.SetOutput(w)
log.SetPrefix(fmt.Sprintf("*** SLACKDUMP RAW [%s]: ", sl))

if sl.IsThread() {
return saveThread(ctx, cl, w, token, sl)
err = saveThread(ctx, cl, w, token, sl)
} else {
return saveConversation(ctx, cl, w, token, sl)
err = saveConversation(ctx, cl, w, token, sl)
}
if closeErr := w.Close(); closeErr != nil && err == nil {
err = closeErr
}
return err
}

func maybeCreate(filename string) (io.WriteCloser, error) {
Expand Down Expand Up @@ -197,7 +200,9 @@ func sendReq(w io.Writer, cl *http.Client, ep string, v url.Values) (bool, error
defer resp.Body.Close()

log.Print("request headers")
resp.Header.Write(w)
if err := resp.Header.Write(w); err != nil {
return false, fmt.Errorf("writing response headers: %w", err)
}

data, err := io.ReadAll(resp.Body)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion cmd/slackdump/internal/diag/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,5 @@ Tools command contains different tools, running which may be requested if you op
cmdUninstall,
cmdUnzip,
cmdUpdate,
// cmdWizDebug,
},
}
22 changes: 22 additions & 0 deletions cmd/slackdump/internal/diag/tools_debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2021-2026 Rustam Gilyazov and Contributors.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//go:build debug

package diag

func init() {
CmdDiag.Commands = append(CmdDiag.Commands, cmdWizDebug)
}
2 changes: 2 additions & 0 deletions cmd/slackdump/internal/diag/wizdebug.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//go:build debug

package diag

import (
Expand Down
6 changes: 0 additions & 6 deletions internal/edge/slacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ func (cl *Client) GetConversationsContextEx(ctx context.Context, p *slack.GetCon
return cl.getConversationsContext(ctx, p, onlyMy)
}

// group type parameter mapping
var channelTypeMap = map[string]string{
structures.CPrivate: string(SCTPrivate),
structures.CPublic: string(SCTPrivateExclude),
}

type searchResult struct {
Channels []slack.Channel
Err error
Expand Down
7 changes: 0 additions & 7 deletions internal/viewer/renderer/slack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ var (
// rte - rich text element
var (
rteTypeHandlers = map[slack.RichTextElementType]func(*Slack, slack.RichTextElement) (string, string, error){}

rteTypeClass = map[slack.RichTextElementType]string{
slack.RTESection: "slack-rich-text-section",
slack.RTEList: "slack-rich-text-list",
slack.RTEQuote: "slack-rich-text-quote",
slack.RTEPreformatted: "slack-rich-text-preformatted",
}
)

func init() {
Expand Down
Loading