Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bram Hagens
api
Commits
39e4a175
Verified
Commit
39e4a175
authored
4 years ago
by
Dean
Browse files
Options
Downloads
Patches
Plain Diff
Fix delete objects bug
parent
c76f6277
No related branches found
Branches containing commit
Tags
v1.4.0
Tags containing commit
No related merge requests found
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
go.mod
+20
-12
20 additions, 12 deletions
go.mod
go.sum
+142
-0
142 additions, 0 deletions
go.sum
lib/db/queries.go
+10
-0
10 additions, 0 deletions
lib/db/queries.go
lib/db/sql.go
+2
-15
2 additions, 15 deletions
lib/db/sql.go
lib/routes/deleteobject.go
+11
-3
11 additions, 3 deletions
lib/routes/deleteobject.go
with
185 additions
and
30 deletions
go.mod
+
20
−
12
View file @
39e4a175
module
owo.codes/whats-this/api
require (
github.com/BurntSushi/toml
v0.3.1 // indirect
github.com/akamensky/base58
v0.0.0-20170920141933-92b0f56f531a
github.com/go-chi/chi
v4.0.1+incompatible
github.com/coreos/go-etcd
v2.0.0+incompatible // indirect
github.com/fsnotify/fsnotify
v1.4.9 // indirect
github.com/go-chi/chi
v4.1.0+incompatible
github.com/go-chi/render
v1.0.1
github.com/go-redis/redis
v6.15.
1
+incompatible
github.com/go-redis/redis
v6.15.
7
+incompatible
github.com/gofrs/uuid
v3.2.0+incompatible
github.com/
kr/pretty
v0.1.0 // indirect
github.com/
lib/pq
v1.0.0
github.com/
lib/pq
v1.3.0
github.com/
mitchellh/mapstructure
v1.2.2 // indirect
github.com/onsi/ginkgo
v1.7.0 // indirect
github.com/onsi/gomega
v1.4.3 // indirect
github.com/pkg/errors
v0.8.1
github.com/rs/zerolog
v1.11.0
github.com/spf13/pflag
v1.0.3
github.com/spf13/viper
v1.3.1
github.com/pelletier/go-toml
v1.7.0 // indirect
github.com/pkg/errors
v0.9.1
github.com/rs/zerolog
v1.18.0
github.com/spf13/afero
v1.2.2 // indirect
github.com/spf13/cast
v1.3.1 // indirect
github.com/spf13/jwalterweatherman
v1.1.0 // indirect
github.com/spf13/pflag
v1.0.5
github.com/spf13/viper
v1.6.2
github.com/stretchr/testify
v1.3.0 // indirect
golang.org/x/net
v0.0.0-20190420063019-afa5a82059c6 // indirect
golang.org/x/sys
v0.0.0-20190419153524-e8e3143a4f4a // indirect
gopkg.in/check.v1
v1.0.0-20180628173108-788fd7840127 // indirect
github.com/ugorji/go/codec
v0.0.0-20181204163529-d75b2dcb6bc8 // indirect
golang.org/x/sys
v0.0.0-20200406155108-e3b113bbe6a4 // indirect
golang.org/x/text
v0.3.2 // indirect
gopkg.in/ini.v1
v1.55.0 // indirect
)
go 1.13
This diff is collapsed.
Click to expand it.
go.sum
+
142
−
0
View file @
39e4a175
This diff is collapsed.
Click to expand it.
lib/db/queries.go
+
10
−
0
View file @
39e4a175
...
...
@@ -246,6 +246,16 @@ func GetObject(bucket, key string) (Object, error) {
return
scanObject
(
row
)
}
// CheckIfObjectExists returns true if an object exists with the specified hash.
func
CheckIfObjectExists
(
sha256
[]
byte
)
(
bool
,
error
)
{
var
count
int
err
:=
DB
.
QueryRow
(
countOfObjectsBySHA256
,
sha256
)
.
Scan
(
&
count
)
if
err
!=
nil
{
return
false
,
err
}
return
count
>
0
,
nil
}
// UpdateObjectToTombstoneByBucketKey sets an object to be a tombstone by bucket and key.
func
UpdateObjectToTombstoneByBucketKey
(
bucket
,
key
string
,
reason
*
string
,
retainAssociatedUser
bool
,
retainHashes
bool
)
error
{
sql
:=
updateObjectToTombstoneByBucketKey
...
...
This diff is collapsed.
Click to expand it.
lib/db/sql.go
+
2
−
15
View file @
39e4a175
...
...
@@ -113,27 +113,14 @@ WHERE
LIMIT 1
`
var
get
ObjectBySHA256
Hash
=
`
var
countOf
Object
s
BySHA256
=
`
SELECT
bucket,
key,
dir,
"type",
dest_url,
content_type,
content_length,
created_at,
deleted_at,
delete_reason,
md5_hash,
sha256_hash,
associated_user
COUNT(*)
FROM
objects
WHERE
"type" = 0,
sha256_hash = $1
LIMIT 1
`
var
updateObjectToTombstoneByBucketKey
=
`
...
...
This diff is collapsed.
Click to expand it.
lib/routes/deleteobject.go
+
11
−
3
View file @
39e4a175
...
...
@@ -90,12 +90,20 @@ func DeleteObject(w http.ResponseWriter, r *http.Request) {
// Delete file from disk if type was 0
if
object
.
Type
==
0
{
destPath
:=
filepath
.
Join
(
viper
.
GetString
(
"files.storageLocation"
),
*
object
.
SHA256Hash
)
err
=
os
.
Remove
(
destPath
)
exists
,
err
:=
db
.
CheckIfObjectExists
(
object
.
SHA256HashBytes
)
if
err
!=
nil
{
log
.
Error
()
.
Err
(
err
)
.
Msg
(
"failed to delete object file from disk
"
)
log
.
Error
()
.
Err
(
err
)
.
Str
(
"hash"
,
*
object
.
SHA256Hash
)
.
Msg
(
"failed to check if file exists
"
)
panic
(
apierrors
.
InternalServerError
)
}
if
!
exists
{
destPath
:=
filepath
.
Join
(
viper
.
GetString
(
"files.storageLocation"
),
*
object
.
SHA256Hash
)
err
=
os
.
Remove
(
destPath
)
if
err
!=
nil
{
log
.
Error
()
.
Err
(
err
)
.
Msg
(
"failed to delete object file from disk"
)
panic
(
apierrors
.
InternalServerError
)
}
}
}
// Return tombstone response
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment