Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
matrix-media-repo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
matrix-media-repo
Commits
5561b94f
Commit
5561b94f
authored
4 years ago
by
Travis Ralston
Browse files
Options
Downloads
Patches
Plain Diff
Add a verify mode to imports
Fixes
https://github.com/turt2live/matrix-media-repo/issues/276
parent
367ed7e0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+4
-0
4 additions, 0 deletions
CHANGELOG.md
README.md
+2
-0
2 additions, 0 deletions
README.md
cmd/gdpr_import/main.go
+22
-1
22 additions, 1 deletion
cmd/gdpr_import/main.go
controllers/data_controller/import_controller.go
+38
-0
38 additions, 0 deletions
controllers/data_controller/import_controller.go
with
66 additions
and
1 deletion
CHANGELOG.md
+
4
−
0
View file @
5561b94f
...
@@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
...
@@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [Unreleased]
## [Unreleased]
### Added
*
Added a
`-verify`
mode to imports to determine if large imports were successful.
### Changed
### Changed
*
`Content-Disposition`
of plain text files now defaults to
`inline`
.
*
`Content-Disposition`
of plain text files now defaults to
`inline`
.
...
...
This diff is collapsed.
Click to expand it.
README.md
+
2
−
0
View file @
5561b94f
...
@@ -120,4 +120,6 @@ Usage of gdpr_import:
...
@@ -120,4 +120,6 @@ Usage of gdpr_import:
The directory for where the entity's exported files are (default "./gdpr-data")
The directory for where the entity's exported files are (default "./gdpr-data")
-migrations string
-migrations string
The absolute path for the migrations folder (default "./migrations")
The absolute path for the migrations folder (default "./migrations")
-verify
If set, no media will be imported and instead be tested to see if they've been imported already
```
```
This diff is collapsed.
Click to expand it.
cmd/gdpr_import/main.go
+
22
−
1
View file @
5561b94f
...
@@ -22,6 +22,7 @@ func main() {
...
@@ -22,6 +22,7 @@ func main() {
configPath
:=
flag
.
String
(
"config"
,
"media-repo.yaml"
,
"The path to the configuration"
)
configPath
:=
flag
.
String
(
"config"
,
"media-repo.yaml"
,
"The path to the configuration"
)
migrationsPath
:=
flag
.
String
(
"migrations"
,
config
.
DefaultMigrationsPath
,
"The absolute path for the migrations folder"
)
migrationsPath
:=
flag
.
String
(
"migrations"
,
config
.
DefaultMigrationsPath
,
"The absolute path for the migrations folder"
)
filesDir
:=
flag
.
String
(
"directory"
,
"./gdpr-data"
,
"The directory for where the entity's exported files are"
)
filesDir
:=
flag
.
String
(
"directory"
,
"./gdpr-data"
,
"The directory for where the entity's exported files are"
)
verifyMode
:=
flag
.
Bool
(
"verify"
,
false
,
"If set, no media will be imported and instead be tested to see if they've been imported already"
)
flag
.
Parse
()
flag
.
Parse
()
// Override config path with config for Docker users
// Override config path with config for Docker users
...
@@ -72,7 +73,6 @@ func main() {
...
@@ -72,7 +73,6 @@ func main() {
}
}
}
}
logrus
.
Info
(
"Starting import..."
)
ctx
:=
rcontext
.
Initial
()
.
LogWithFields
(
logrus
.
Fields
{
"flagDir"
:
*
filesDir
})
ctx
:=
rcontext
.
Initial
()
.
LogWithFields
(
logrus
.
Fields
{
"flagDir"
:
*
filesDir
})
f
,
err
:=
os
.
Open
(
files
[
manifestIdx
])
f
,
err
:=
os
.
Open
(
files
[
manifestIdx
])
...
@@ -80,6 +80,27 @@ func main() {
...
@@ -80,6 +80,27 @@ func main() {
panic
(
err
)
panic
(
err
)
}
}
defer
f
.
Close
()
defer
f
.
Close
()
if
*
verifyMode
{
found
,
expected
,
missingIds
,
err
:=
data_controller
.
VerifyImport
(
f
,
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
logrus
.
Info
(
"Known imported media IDs: "
,
found
)
logrus
.
Info
(
"Expected media IDs: "
,
expected
)
if
len
(
missingIds
)
>
0
{
for
_
,
mxc
:=
range
missingIds
{
logrus
.
Error
(
"Expected media ID but was not present: "
,
mxc
)
}
logrus
.
Warn
(
"Not all media is present. See logs for details."
)
os
.
Exit
(
1
)
}
logrus
.
Info
(
"All media present!"
)
return
// exit 0
}
logrus
.
Info
(
"Starting import..."
)
task
,
importId
,
err
:=
data_controller
.
StartImport
(
f
,
ctx
)
task
,
importId
,
err
:=
data_controller
.
StartImport
(
f
,
ctx
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
err
)
panic
(
err
)
...
...
This diff is collapsed.
Click to expand it.
controllers/data_controller/import_controller.go
+
38
−
0
View file @
5561b94f
...
@@ -30,6 +30,44 @@ type importUpdate struct {
...
@@ -30,6 +30,44 @@ type importUpdate struct {
var
openImports
=
&
sync
.
Map
{}
// importId => updateChan
var
openImports
=
&
sync
.
Map
{}
// importId => updateChan
func
VerifyImport
(
data
io
.
Reader
,
ctx
rcontext
.
RequestContext
)
(
int
,
int
,
[]
string
,
error
)
{
// Prepare the first update for the import (sync, so we can error)
// We do this before anything else because if the archive is invalid then we shouldn't
// even bother with an import.
results
,
err
:=
processArchive
(
data
)
if
err
!=
nil
{
return
0
,
0
,
nil
,
err
}
manifestFile
,
ok
:=
results
[
"manifest.json"
]
if
!
ok
{
return
0
,
0
,
nil
,
errors
.
New
(
"no manifest provided in data package"
)
}
archiveManifest
:=
&
Manifest
{}
err
=
json
.
Unmarshal
(
manifestFile
.
Bytes
(),
archiveManifest
)
if
err
!=
nil
{
return
0
,
0
,
nil
,
err
}
expected
:=
0
found
:=
0
missing
:=
make
([]
string
,
0
)
db
:=
storage
.
GetDatabase
()
.
GetMediaStore
(
ctx
)
for
mxc
,
r
:=
range
archiveManifest
.
Media
{
ctx
.
Log
.
Info
(
"Checking file: "
,
mxc
)
expected
++
_
,
err
=
db
.
Get
(
r
.
Origin
,
r
.
MediaId
)
if
err
==
nil
{
found
++
}
else
{
missing
=
append
(
missing
,
mxc
)
}
}
return
found
,
expected
,
missing
,
nil
}
func
StartImport
(
data
io
.
Reader
,
ctx
rcontext
.
RequestContext
)
(
*
types
.
BackgroundTask
,
string
,
error
)
{
func
StartImport
(
data
io
.
Reader
,
ctx
rcontext
.
RequestContext
)
(
*
types
.
BackgroundTask
,
string
,
error
)
{
// Prepare the first update for the import (sync, so we can error)
// Prepare the first update for the import (sync, so we can error)
// We do this before anything else because if the archive is invalid then we shouldn't
// We do this before anything else because if the archive is invalid then we shouldn't
...
...
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