2014-09-19 1 views
0

libarchive 라이브러리를 사용하여 아카이브 항목의 이름을 바꾸려고합니다. 특히 나는 archive_entry_set_pathname 함수를 사용하고 있습니다.libarchive를 사용하여 아카이브의 비어 있지 않은 디렉토리의 이름을 변경하십시오.

파일과 빈 디렉토리의 이름이 올바르게 변경되었지만 디렉토리가 비어 있지 않으면 불행히도 작동하지 않습니다. 새 이름이 아닌 디렉토리가 대상 디렉토리의 형제로 생성됩니다. 옛 이름이야.

관련 코드 : 비어 있지 않은 디렉토리 잘못 무엇

... 
while (archive_read_next_header(inputArchive, &entry) == ARCHIVE_OK) { 
     if (file == QFile::decodeName(archive_entry_pathname(entry))) { 
      // FIXME: not working with non-empty directories 
      archive_entry_set_pathname(entry, QFile::encodeName(newPath));  
     } 

     int header_response; 
     if ((header_response = archive_write_header(outputArchive, entry)) == ARCHIVE_OK) { 
      ... // write the (new) outputArchive on disk 
     } 
    } 

?

답변

1

아카이브에서 파일은 아카이브의 루트를 기준으로 전체 경로 이름과 함께 저장됩니다. 코드가 디렉토리 항목과 만 일치하면 해당 디렉토리 아래의 모든 항목을 일치시키고 이름을 바꿔야합니다. 나는 Qt 전문가가 아니며이 코드를 사용하지 않았지만 아이디어를 얻을 수 있습니다.

QStringLiteral oldPath("foo/"); 
QStringLiteral newPath("bar/"); 
while (archive_read_next_header(inputArchive, &entry) == ARCHIVE_OK) { 
    QString arEntryPath = QFile::decodeName(archive_entry_pathname(entry)); 
    if(arEntryPath.startsWith(oldPath) { 
     arEntryPath.replace(0, oldPath.length(), newPath); 
     archive_entry_set_pathname(entry, QFile::encodeName(arEntryPath)); 
    } 

    int header_response; 
    if ((header_response = archive_write_header(outputArchive, entry)) == ARCHIVE_OK) { 
     ... // write the (new) outputArchive on disk 
    } 
}