@@ -80,10 +80,33 @@ def empty_dir(path):
8080 ):
8181 if not os .listdir (data_path ):
8282 logger .info (f"Migrating data from { original_path } → { data_path } " )
83- shutil .copytree (
84- original_path , data_path , dirs_exist_ok = True , symlinks = True
85- )
86- chown_recursive (data_path , user_id , group_id )
83+ try :
84+ shutil .copytree (
85+ original_path , data_path , dirs_exist_ok = True , symlinks = True
86+ )
87+ chown_recursive (data_path , user_id , group_id )
88+ original_size = sum (
89+ os .path .getsize (os .path .join (root , file ))
90+ for root , _ , files in os .walk (original_path )
91+ for file in files
92+ )
93+ data_size = sum (
94+ os .path .getsize (os .path .join (root , file ))
95+ for root , _ , files in os .walk (data_path )
96+ for file in files
97+ )
98+ if original_size != data_size :
99+ raise Exception (
100+ f"Data size mismatch: { original_size } bytes in original, { data_size } bytes in data path"
101+ )
102+ logger .debug (
103+ f"Data migration successful: { original_path } (bytes: { original_size } ) → { data_path } (bytes: { data_size } )"
104+ )
105+ except Exception as e :
106+ logger .error (
107+ f"Error copying data from { original_path } to { data_path } : { e } "
108+ )
109+ raise
87110 else :
88111 logger .debug (f"{ data_path } already has content, skipping copy" )
89112
@@ -100,10 +123,20 @@ def empty_dir(path):
100123 if not os .path .exists (original_path ):
101124 os .makedirs (os .path .dirname (original_path ), exist_ok = True )
102125 os .symlink (data_path , original_path )
103- logger .debug (f"Created symlink: { original_path } → { data_path } " )
126+ if (
127+ os .path .islink (original_path )
128+ and os .readlink (original_path ) == data_path
129+ ):
130+ logger .debug (f"Created symlink: { original_path } → { data_path } " )
131+ else :
132+ raise Exception (
133+ f"Failed to create symlink: { original_path } → { data_path } "
134+ )
104135
105136 except Exception as e :
106- logger .error (f"Migration failed for { original_path } to { data_path } : { e } " )
137+ raise RuntimeError (
138+ f"Migration failed for { original_path } to { data_path } : { e } "
139+ ) from e
107140
108141
109142def cleanup_broken_symlinks (directory ):
@@ -120,29 +153,34 @@ def cleanup_broken_symlinks(directory):
120153
121154
122155def migrate_symlinks ():
123- data_root = "/data"
124- if is_mount (data_root ):
125- cleanup_broken_symlinks (data_root )
126-
127- symlink_map = [
128- ("/zurg/RD" , os .path .join (data_root , "zurg_RD" )),
129- ("/riven/backend/data" , os .path .join (data_root , "riven" )),
130- ("/postgres_data" , os .path .join (data_root , "postgres" )),
131- ("/pgadmin/data" , os .path .join (data_root , "pgadmin" )),
132- ("/zilean/app/data" , os .path .join (data_root , "zilean" )),
133- ("/plex_debrid/config" , os .path .join (data_root , "plex_debrid" )),
134- ("/cli_debrid/data" , os .path .join (data_root , "cli_debrid" )),
135- ("/phalanx_db/data" , os .path .join (data_root , "phalanx_db" )),
136- ("/decypharr" , os .path .join (data_root , "decypharr" )),
137- ("/plex" , os .path .join (data_root , "plex" )),
138- ]
139-
140- for original_path , data_path in symlink_map :
141- migrate_and_symlink (original_path , data_path )
142- else :
143- logger .warning (
144- f"Data root { data_root } is not a mount. Skipping symlink migration."
145- )
156+ data_root = str (config .get ("data_root" )) or "/data"
157+ logger .debug (f"Data root for symlink migration: { data_root } " )
158+ try :
159+ if is_mount (data_root ):
160+ cleanup_broken_symlinks (data_root )
161+
162+ symlink_map = [
163+ ("/zurg/RD" , os .path .join (data_root , "zurg_RD" )),
164+ ("/riven/backend/data" , os .path .join (data_root , "riven" )),
165+ ("/postgres_data" , os .path .join (data_root , "postgres" )),
166+ ("/pgadmin/data" , os .path .join (data_root , "pgadmin" )),
167+ ("/zilean/app/data" , os .path .join (data_root , "zilean" )),
168+ ("/plex_debrid/config" , os .path .join (data_root , "plex_debrid" )),
169+ ("/cli_debrid/data" , os .path .join (data_root , "cli_debrid" )),
170+ ("/phalanx_db/data" , os .path .join (data_root , "phalanx_db" )),
171+ ("/decypharr" , os .path .join (data_root , "decypharr" )),
172+ ("/plex" , os .path .join (data_root , "plex" )),
173+ ]
174+
175+ for original_path , data_path in symlink_map :
176+ migrate_and_symlink (original_path , data_path )
177+ else :
178+ logger .warning (
179+ f"Data root { data_root } is not a mount. Skipping symlink migration."
180+ )
181+ except Exception as e :
182+ logger .error (f"Error during symlink migration: { e } " )
183+ raise
146184
147185
148186def create_system_user (username = "DUMB" ):
0 commit comments