@@ -89,6 +89,7 @@ impl CommitWriter {
8989 struct Directories {
9090 main_dir : PathBuf ,
9191 bytecode_main_dir : PathBuf ,
92+ bytecode_commit_dir : PathBuf ,
9293 memory_main_dir : PathBuf ,
9394 leaf_main_dir : PathBuf ,
9495 }
@@ -100,6 +101,10 @@ impl CommitWriter {
100101 let bytecode_main_dir = main_dir. join ( BYTECODE_DIR ) ;
101102 fs:: create_dir_all ( & bytecode_main_dir) ?;
102103
104+ let bytecode_commit_dir =
105+ bytecode_main_dir. join ( commit_id. as_ref ( ) ) ;
106+ fs:: create_dir_all ( & bytecode_commit_dir) ?;
107+
103108 let memory_main_dir = main_dir. join ( MEMORY_DIR ) ;
104109 fs:: create_dir_all ( & memory_main_dir) ?;
105110
@@ -109,6 +114,7 @@ impl CommitWriter {
109114 Directories {
110115 main_dir,
111116 bytecode_main_dir,
117+ bytecode_commit_dir,
112118 memory_main_dir,
113119 leaf_main_dir,
114120 }
@@ -149,13 +155,33 @@ impl CommitWriter {
149155 let metadata_main_path =
150156 bytecode_main_path. with_extension ( METADATA_EXTENSION ) ;
151157
158+ let bytecode_commit_path =
159+ directories. bytecode_commit_dir . join ( & contract_hex) ;
160+ let module_commit_path =
161+ bytecode_commit_path. with_extension ( OBJECTCODE_EXTENSION ) ;
162+ let metadata_commit_path =
163+ bytecode_commit_path. with_extension ( METADATA_EXTENSION ) ;
164+
152165 // If the contract is new, we write the bytecode, module, and
153166 // metadata files to disk.
154167 if contract_data. is_new {
155168 // we write them to the main location
156- fs:: write ( bytecode_main_path, & contract_data. bytecode ) ?;
157- fs:: write ( module_main_path, contract_data. module . serialize ( ) ) ?;
158- fs:: write ( metadata_main_path, & contract_data. metadata ) ?;
169+ fs:: write ( bytecode_commit_path, & contract_data. bytecode ) ?;
170+ fs:: write (
171+ module_commit_path,
172+ contract_data. module . serialize ( ) ,
173+ ) ?;
174+ fs:: write ( metadata_commit_path, & contract_data. metadata ) ?;
175+ // if main does not have this contract yet, we store it there as
176+ // well
177+ if !bytecode_main_path. is_file ( ) {
178+ fs:: write ( bytecode_main_path, & contract_data. bytecode ) ?;
179+ fs:: write (
180+ module_main_path,
181+ contract_data. module . serialize ( ) ,
182+ ) ?;
183+ fs:: write ( metadata_main_path, & contract_data. metadata ) ?;
184+ }
159185 dirty = true ;
160186 }
161187 if dirty {
0 commit comments