Last active
April 16, 2025 07:07
-
-
Save jochumdev/6c557f108eaba24f7866659830ce4e03 to your computer and use it in GitHub Desktop.
ocis->oc decomposed rewrite mpack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module github.com/opencloud-eu/mpak-convert | |
go 1.24 | |
require github.com/shamaton/msgpack/v2 v2.2.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Copyright 2025 Rene Jochum | |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | |
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | |
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. | |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"maps" | |
"os" | |
"path/filepath" | |
"slices" | |
"strings" | |
"github.com/shamaton/msgpack/v2" | |
) | |
func main() { | |
rewriteCmd := flag.NewFlagSet("rewrite", flag.ExitOnError) | |
rewritePrefix := rewriteCmd.String("prefix", "user.ocis.", "extended attributes prefix to match") | |
rewriteReplace := rewriteCmd.String("replace", "user.oc.", "replacement to use") | |
rewriteNoop := rewriteCmd.Bool("noop", false, "do not actually rewrite attributes") | |
if len(os.Args) < 3 { | |
fmt.Println("expected command and path") | |
os.Exit(1) | |
} | |
oneOf := []string{*rewritePrefix + "id", *rewritePrefix + "name", *rewritePrefix + "type"} | |
switch os.Args[1] { | |
case "rewrite": | |
rewriteCmd.Parse(os.Args[2:]) | |
err := filepath.Walk(rewriteCmd.Args()[0], func(path string, info os.FileInfo, err error) error { | |
if err != nil { | |
return err | |
} | |
if !strings.HasSuffix(path, ".mpk") { | |
return nil | |
} | |
fmt.Println(path, info.Size()) | |
b, err := os.ReadFile(path) | |
if err != nil { | |
return err | |
} | |
m := map[string][]byte{} | |
if err := msgpack.Unmarshal(b, &m); err != nil { | |
return err | |
} | |
fileKeys := slices.Collect(maps.Keys(m)) | |
// Skip files that do not have the prefix | |
found := false | |
for _, one := range oneOf { | |
if slices.Contains(fileKeys, one) { | |
found = true | |
break | |
} | |
} | |
if !found { | |
fmt.Println("# skipping", path) | |
return nil | |
} | |
for attr, value := range m { | |
if strings.HasPrefix(attr, *rewritePrefix) { | |
newAttr := *rewriteReplace + strings.TrimPrefix(attr, *rewritePrefix) | |
fmt.Println("#", attr, "->", newAttr) | |
if *rewriteNoop { | |
continue | |
} | |
// actual rewrite | |
m[newAttr] = value | |
// TODO: make optional? --remove? --noremove? | |
delete(m, attr) | |
} | |
} | |
b, err = msgpack.Marshal(m) | |
if err != nil { | |
return err | |
} | |
return os.WriteFile(path, b, 0600) | |
}) | |
if err != nil { | |
fmt.Println(err) | |
} | |
default: | |
fmt.Println("unknown command") | |
os.Exit(1) | |
} | |
} |
It broke now not all mpk have the key type
you only checking for that now.
Ex:
{
"user.ocis.space.id": <bin of size 36>,
"user.ocis.propagation": <bin of size 1>,
"user.ocis.owner.id": <bin of size 36>,
"user.ocis.space.type": <bin of size 8>,
"user.ocis.space.alias": <bin of size 14>,
"user.ocis.owner.type": <bin of size 7>,
"user.ocis.tmp.etag": <bin of size 0>,
"user.ocis.tmtime": <bin of size 30>,
"user.ocis.treesize": <bin of size 8>,
"user.ocis.name": <bin of size 5>,
"user.ocis.id": <bin of size 36>,
"user.ocis.owner.idp": <bin of size 48>,
"user.ocis.space.name": <bin of size 5>
}
Many thanks! I revert the latest change on type
.
ok, done.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
!! WARNING !!
Please TRY it on a clone/copy of your data first. It can mess up your data and you won't be able to get it back even when reverting to oCIS
How to migrate oCIS to opencloud using decomposeds3
This was tested with oCIS with decomposeds3 enabled. It probably will work on decomposedfs, but it is untested by me.
Since you are coming from oCIS you probably used
ocis
ors3ng
as storage driver.Make sure to add one of those options because opencloud default driver is
posix
1. Run the above script against the
storage
folder.mpak-convert rewrite --prefix user.ocis. --replace user.oc. /path/to/storage
If you're inside the storage folder use
.
mpak-convert rewrite --prefix user.ocis. --replace user.oc. .
2. In addition to the above, you have to execute the following commands in the
storage
folderReplace
ocis-roles
withopencloud-roles
in the roles bundles.find . -type f -print0 | xargs -0 sed -i 's/ocis-roles/opencloud-roles/g'
Replace
ocis-accounts
withopencloud-accounts
in the accounts bundles.find . -type f -print0 | xargs -0 sed -i 's/ocis-accounts/opencloud-accounts/g'
When using custom roles via ENV
SETTINGS_BUNDLES_PATH
The env needs to be removed for the first start. It can be added after opencloud started the first time.3. IDM
When coming from oCIS, and you used the internal idm you need to rename the
ocis.boltdb
toidm.boltdb
in thedata/idm
folderIf you used an external LDAP server, you're probably good.
For the internal IDM, add the following ENV variables to your docker file.