public Path resolveConflictsIfNecessary ( Path ciphertextPath , String dirId ) throws IOException { String ciphertextFileName = ciphertextPath . getFileName ( ) . toString ( ) ; String basename = StringUtils . removeEnd ( ciphertextFileName , LONG_NAME_FILE_EXT ) ; Matcher m = CIPHERTEXT_FILENAME_PATTERN . matcher ( basename ) ; if ( ! m . matches ( ) && m . find ( 0 ) ) { // no full match, but still contains base32 -> partial match return resolveConflict ( ciphertextPath , m . group ( 0 ) , dirId ) ; } else { // full match or no match at all -> nothing to resolve return ciphertextPath ; } }
Checks if the name of the file represented by the given ciphertextPath is a valid ciphertext name without any additional chars . If any unexpected chars are found on the name but it still contains an authentic ciphertext it is considered a conflicting file . Conflicting files will be given a new name . The caller must use the path returned by this function after invoking it as the given ciphertextPath might be no longer valid .