Writer file corrupted after unzip / zip

I’m working on a project that will potentially involve unzipping an .odt file, modifying contents.xml and rezipping. First, I’m trying to make sure this will work on a test case but I can’t seem to even unzip and re-zip without corrupting the file.

I’m running LibreOffice 5.2.7.2 under Debian Stretch (9).

I do the following:

Create a test file “test_doc.odt”. Open with Writer, add the contents “12345” and save. File opens fine.

Now I try to unzip the file, and re-zip it without any modification:

donald@IIF-Dev:~/Projects/libre_test$ mkdir test_doc
donald@IIF-Dev:~/Projects/libre_test$ unzip test_doc.odt -d test_doc
Archive:  test_doc.odt
 extracting: test_doc/mimetype       
 extracting: test_doc/Thumbnails/thumbnail.png  
  inflating: test_doc/content.xml    
  inflating: test_doc/styles.xml     
  inflating: test_doc/meta.xml       
  inflating: test_doc/settings.xml   
   creating: test_doc/Configurations2/toolpanel/
   creating: test_doc/Configurations2/progressbar/
   creating: test_doc/Configurations2/toolbar/
   creating: test_doc/Configurations2/menubar/
   creating: test_doc/Configurations2/floater/
  inflating: test_doc/Configurations2/accelerator/current.xml  
   creating: test_doc/Configurations2/statusbar/
   creating: test_doc/Configurations2/images/Bitmaps/
   creating: test_doc/Configurations2/popupmenu/
  inflating: test_doc/manifest.rdf   
  inflating: test_doc/META-INF/manifest.xml  
donald@IIF-Dev:~/Projects/libre_test$ zip -r -0 test_modified.zip test_doc
  adding: test_doc/ (stored 0%)
  adding: test_doc/mimetype (stored 0%)
  adding: test_doc/META-INF/ (stored 0%)
  adding: test_doc/META-INF/manifest.xml (stored 0%)
  adding: test_doc/settings.xml (stored 0%)
  adding: test_doc/styles.xml (stored 0%)
  adding: test_doc/content.xml (stored 0%)
  adding: test_doc/Configurations2/ (stored 0%)
  adding: test_doc/Configurations2/statusbar/ (stored 0%)
  adding: test_doc/Configurations2/menubar/ (stored 0%)
  adding: test_doc/Configurations2/progressbar/ (stored 0%)
  adding: test_doc/Configurations2/floater/ (stored 0%)
  adding: test_doc/Configurations2/toolpanel/ (stored 0%)
  adding: test_doc/Configurations2/images/ (stored 0%)
  adding: test_doc/Configurations2/images/Bitmaps/ (stored 0%)
  adding: test_doc/Configurations2/popupmenu/ (stored 0%)
  adding: test_doc/Configurations2/toolbar/ (stored 0%)
  adding: test_doc/Configurations2/accelerator/ (stored 0%)
  adding: test_doc/Configurations2/accelerator/current.xml (stored 0%)
  adding: test_doc/Thumbnails/ (stored 0%)
  adding: test_doc/Thumbnails/thumbnail.png (stored 0%)
  adding: test_doc/manifest.rdf (stored 0%)
  adding: test_doc/meta.xml (stored 0%)
donald@IIF-Dev:~/Projects/libre_test$ 
donald@IIF-Dev:~/Projects/libre_test$ mv test_modified.zip test_modified.odt
donald@IIF-Dev:~/Projects/libre_test$ ls -ahl
total 56K
drwxr-xr-x 3 donald donald 4.0K Apr  5 09:44 .
drwxr-xr-x 9 donald donald 4.0K Apr  5 08:15 ..
drwxr-xr-x 5 donald donald 4.0K Apr  5 09:42 test_doc
-rw-r--r-- 1 donald donald 8.0K Apr  5 09:25 test_doc.odt
-rw-r--r-- 1 donald donald  34K Apr  5 09:42 test_modified.odt
donald@IIF-Dev:~/Projects/libre_test$

When I try to open the resulting file, LibreOffice tells me “The file ‘test_modified.odt’ is corrupt and therefore cannot be opened.” Repairs do not succeed.

I’m thinking I need to do something with the flags used in zip or unzip, but I can’t figure out what.

Any help would be much appreciated!

I realized my error - I was zipping the parent folder “test_doc”.

cd test_doc
zip -r ../test_doc.odt 

solved the problem. Thanks!

.