@@ -143,14 +143,13 @@ func (fs *FileStore) GetTempFilePath(allocID, connID, fileName, filePathHash str
143143 return fs .getTempPathForFile (allocID , fileName , filePathHash , connID )
144144}
145145
146- func (fs * FileStore ) MoveToFilestore (allocID , hash string ) error {
147-
148- fPath , err := fs .GetPathForFile (allocID , hash )
146+ func (fs * FileStore ) MoveToFilestore (allocID , hash string , version int ) error {
147+ fPath , err := fs .GetPathForFile (allocID , hash , version )
149148 if err != nil {
150149 return common .NewError ("get_file_path_error" , err .Error ())
151150 }
152151
153- preCommitPath := fs .getPreCommitPathForFile (allocID , hash )
152+ preCommitPath := fs .getPreCommitPathForFile (allocID , hash , version )
154153
155154 err = createDirs (filepath .Dir (fPath ))
156155 if err != nil {
@@ -161,9 +160,9 @@ func (fs *FileStore) MoveToFilestore(allocID, hash string) error {
161160 return nil
162161}
163162
164- func (fs * FileStore ) DeleteFromFilestore (allocID , hash string ) error {
163+ func (fs * FileStore ) DeleteFromFilestore (allocID , hash string , version int ) error {
165164
166- fPath , err := fs .GetPathForFile (allocID , hash )
165+ fPath , err := fs .GetPathForFile (allocID , hash , version )
167166 if err != nil {
168167 return common .NewError ("get_file_path_error" , err .Error ())
169168 }
@@ -203,7 +202,7 @@ func (fs *FileStore) CommitWrite(allocID, conID string, fileData *FileInputData)
203202 fileHash = fileData .ThumbnailHash
204203 }
205204
206- preCommitPath := fs .getPreCommitPathForFile (allocID , fileHash )
205+ preCommitPath := fs .getPreCommitPathForFile (allocID , fileHash , VERSION )
207206
208207 err := createDirs (filepath .Dir (preCommitPath ))
209208 if err != nil {
@@ -323,9 +322,9 @@ func (fs *FileStore) CommitWrite(allocID, conID string, fileData *FileInputData)
323322 return true , nil
324323}
325324
326- func (fs * FileStore ) GetFilePathSize (allocID , filehash , thumbHash string ) (int64 , int64 , error ) {
325+ func (fs * FileStore ) GetFilePathSize (allocID , filehash , thumbHash string , version int ) (int64 , int64 , error ) {
327326
328- filePath , err := fs .GetPathForFile (allocID , filehash )
327+ filePath , err := fs .GetPathForFile (allocID , filehash , version )
329328
330329 if err != nil {
331330 return 0 , 0 , err
@@ -340,7 +339,7 @@ func (fs *FileStore) GetFilePathSize(allocID, filehash, thumbHash string) (int64
340339 }
341340 var thumbSize int64
342341 if thumbHash != "" {
343- thumbPath , err := fs .GetPathForFile (allocID , thumbHash )
342+ thumbPath , err := fs .GetPathForFile (allocID , thumbHash , version )
344343 if err != nil {
345344 return 0 , 0 , err
346345 }
@@ -356,9 +355,9 @@ func (fs *FileStore) GetFilePathSize(allocID, filehash, thumbHash string) (int64
356355}
357356
358357// Only decreasing the file size and number. Not deleting the file
359- func (fs * FileStore ) DeleteFile (allocID , validationRoot string ) error {
358+ func (fs * FileStore ) DeleteFile (allocID , validationRoot string , version int ) error {
360359
361- fileObjectPath , err := fs .GetPathForFile (allocID , validationRoot )
360+ fileObjectPath , err := fs .GetPathForFile (allocID , validationRoot , version )
362361 if err != nil {
363362 return err
364363 }
@@ -439,9 +438,9 @@ func (fs *FileStore) GetFileThumbnail(readBlockIn *ReadBlockInput) (*FileDownloa
439438 }
440439 if readBlockIn .IsPrecommit {
441440 fileObjectPath = fs .getPreCommitPathForFile (readBlockIn .AllocationID ,
442- readBlockIn .Hash )
441+ readBlockIn .Hash , readBlockIn . FilestoreVersion )
443442 } else {
444- fileObjectPath , err = fs .GetPathForFile (readBlockIn .AllocationID , readBlockIn .Hash )
443+ fileObjectPath , err = fs .GetPathForFile (readBlockIn .AllocationID , readBlockIn .Hash , readBlockIn . FilestoreVersion )
445444 if err != nil {
446445 return nil , common .NewError ("get_file_path_error" , err .Error ())
447446 }
@@ -450,7 +449,7 @@ func (fs *FileStore) GetFileThumbnail(readBlockIn *ReadBlockInput) (*FileDownloa
450449 file , err := os .Open (fileObjectPath )
451450 if err != nil {
452451 if readBlockIn .IsPrecommit {
453- fileObjectPath , err = fs .GetPathForFile (readBlockIn .AllocationID , readBlockIn .Hash )
452+ fileObjectPath , err = fs .GetPathForFile (readBlockIn .AllocationID , readBlockIn .Hash , readBlockIn . FilestoreVersion )
454453 if err != nil {
455454 return nil , common .NewError ("get_file_path_error" , err .Error ())
456455 }
@@ -519,17 +518,18 @@ func (fs *FileStore) GetFileBlock(readBlockIn *ReadBlockInput) (*FileDownloadRes
519518 return nil , common .NewError ("invalid_block_number" , "Invalid block number. Start block number cannot be negative" )
520519 }
521520 if readBlockIn .IsPrecommit {
522- fileObjectPath = fs .getPreCommitPathForFile (readBlockIn .AllocationID , readBlockIn .Hash )
521+ fileObjectPath = fs .getPreCommitPathForFile (readBlockIn .AllocationID , readBlockIn .Hash , readBlockIn . FilestoreVersion )
523522 } else {
524- fileObjectPath , err = fs .GetPathForFile (readBlockIn .AllocationID , readBlockIn .Hash )
523+ fileObjectPath , err = fs .GetPathForFile (readBlockIn .AllocationID , readBlockIn .Hash , readBlockIn . FilestoreVersion )
525524 if err != nil {
526525 return nil , common .NewError ("get_file_path_error" , err .Error ())
527526 }
528527 }
528+
529529 file , err := os .Open (fileObjectPath )
530530 if err != nil {
531531 if readBlockIn .IsPrecommit {
532- fileObjectPath , err = fs .GetPathForFile (readBlockIn .AllocationID , readBlockIn .Hash )
532+ fileObjectPath , err = fs .GetPathForFile (readBlockIn .AllocationID , readBlockIn .Hash , readBlockIn . FilestoreVersion )
533533 if err != nil {
534534 return nil , common .NewError ("get_file_path_error" , err .Error ())
535535 }
@@ -609,9 +609,9 @@ func (fs *FileStore) GetBlocksMerkleTreeForChallenge(in *ChallengeReadBlockInput
609609 }
610610
611611 if in .IsPrecommit {
612- fileObjectPath = fs .getPreCommitPathForFile (in .AllocationID , in .Hash )
612+ fileObjectPath = fs .getPreCommitPathForFile (in .AllocationID , in .Hash , in . FilestoreVersion )
613613 } else {
614- fileObjectPath , err = fs .GetPathForFile (in .AllocationID , in .Hash )
614+ fileObjectPath , err = fs .GetPathForFile (in .AllocationID , in .Hash , in . FilestoreVersion )
615615 if err != nil {
616616 return nil , err
617617 }
@@ -620,7 +620,7 @@ func (fs *FileStore) GetBlocksMerkleTreeForChallenge(in *ChallengeReadBlockInput
620620 file , err := os .Open (fileObjectPath )
621621 if err != nil {
622622 if in .IsPrecommit {
623- fileObjectPath , err = fs .GetPathForFile (in .AllocationID , in .Hash )
623+ fileObjectPath , err = fs .GetPathForFile (in .AllocationID , in .Hash , in . FilestoreVersion )
624624 if err != nil {
625625 return nil , common .NewError ("get_file_path_error" , err .Error ())
626626 }
@@ -792,12 +792,15 @@ func (fs *FileStore) getAllocDir(allocID string) string {
792792 return filepath .Join (fs .mp , getPartialPath (allocID , getDirLevelsForAllocations ()))
793793}
794794
795- func (fs * FileStore ) GetPathForFile (allocID , hash string ) (string , error ) {
795+ func (fs * FileStore ) GetPathForFile (allocID , hash string , version int ) (string , error ) {
796796 if len (allocID ) != 64 || len (hash ) != 64 {
797797 return "" , errors .New ("length of allocationID/hash must be 64" )
798798 }
799-
800- return filepath .Join (fs .getAllocDir (allocID ), getPartialPath (hash , getDirLevelsForFiles ())), nil
799+ var versionStr string
800+ if version > 0 {
801+ versionStr = fmt .Sprintf ("%d" , version )
802+ }
803+ return filepath .Join (fs .getAllocDir (allocID ), getPartialPath (hash , getDirLevelsForFiles ())+ versionStr ), nil
801804}
802805
803806// getPath returns "/" separated strings with the given levels.
@@ -827,9 +830,14 @@ func (fs *FileStore) getTempPathForFile(allocId, fileName, pathHash, connectionI
827830 return filepath .Join (fs .getAllocTempDir (allocId ), fileName + "." + pathHash + "." + connectionID )
828831}
829832
830- func (fs * FileStore ) getPreCommitPathForFile (allocID , hash string ) string {
833+ func (fs * FileStore ) getPreCommitPathForFile (allocID , hash string , version int ) string {
834+
835+ var versionStr string
836+ if version > 0 {
837+ versionStr = fmt .Sprintf ("%d" , version )
838+ }
831839
832- return filepath .Join (fs .getPreCommitDir (allocID ), getPartialPath (hash , getDirLevelsForFiles ()))
840+ return filepath .Join (fs .getPreCommitDir (allocID ), getPartialPath (hash , getDirLevelsForFiles ())+ versionStr )
833841}
834842
835843func (fs * FileStore ) updateAllocTempFileSize (allocID string , size int64 ) {
0 commit comments