2023-03-12 16:00:57 +01:00
|
|
|
// GoToSocial
|
|
|
|
// Copyright (C) GoToSocial Authors admin@gotosocial.org
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
//
|
|
|
|
// 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 <http://www.gnu.org/licenses/>.
|
2022-11-25 18:23:42 +01:00
|
|
|
|
|
|
|
package prune
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/superseriousbusiness/gotosocial/cmd/gotosocial/action"
|
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/config"
|
2023-06-22 21:46:36 +02:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
|
2022-11-25 18:23:42 +01:00
|
|
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Orphaned prunes orphaned media from storage.
|
|
|
|
var Orphaned action.GTSAction = func(ctx context.Context) error {
|
2023-06-22 21:46:36 +02:00
|
|
|
// Setup pruning utilities.
|
2023-02-11 12:48:38 +01:00
|
|
|
prune, err := setupPrune(ctx)
|
2022-11-25 18:23:42 +01:00
|
|
|
if err != nil {
|
2023-02-11 12:48:38 +01:00
|
|
|
return err
|
2022-11-25 18:23:42 +01:00
|
|
|
}
|
|
|
|
|
2023-06-22 21:46:36 +02:00
|
|
|
defer func() {
|
|
|
|
// Ensure pruner gets shutdown on exit.
|
2023-08-17 18:26:21 +02:00
|
|
|
if err := prune.shutdown(); err != nil {
|
2023-06-22 21:46:36 +02:00
|
|
|
log.Error(ctx, err)
|
|
|
|
}
|
|
|
|
}()
|
2022-11-25 18:23:42 +01:00
|
|
|
|
2023-06-22 21:46:36 +02:00
|
|
|
if config.GetAdminMediaPruneDryRun() {
|
|
|
|
log.Info(ctx, "prune DRY RUN")
|
|
|
|
ctx = gtscontext.SetDryRun(ctx)
|
2022-11-25 18:23:42 +01:00
|
|
|
}
|
|
|
|
|
2023-06-22 21:46:36 +02:00
|
|
|
// Perform the actual pruning with logging.
|
|
|
|
prune.cleaner.Media().LogPruneOrphaned(ctx)
|
|
|
|
|
|
|
|
// Perform a cleanup of storage (for removed local dirs).
|
|
|
|
if err := prune.storage.Storage.Clean(ctx); err != nil {
|
|
|
|
log.Error(ctx, "error cleaning storage: %v", err)
|
2022-11-25 18:23:42 +01:00
|
|
|
}
|
|
|
|
|
2023-06-22 21:46:36 +02:00
|
|
|
return nil
|
2022-11-25 18:23:42 +01:00
|
|
|
}
|