Bug 1417093 - remove symlink support from our nsZipArchive extract implementation because it's unused and has issues, r=mossop

MozReview-Commit-ID: FZ7hy3ATw1i

--HG--
extra : rebase_source : 531b46c24db1791a0dd8ca4afd4021cb2ce4f126
This commit is contained in:
Gijs Kruitbosch 2017-11-21 16:25:46 +00:00
parent 90fbe28861
commit 01809dc8fa
4 changed files with 2 additions and 65 deletions

View File

@ -74,9 +74,6 @@ static const uint16_t kSyntheticDate = (1 + (1 << 5) + (0 << 9));
static uint16_t xtoint(const uint8_t *ii);
static uint32_t xtolong(const uint8_t *ll);
static uint32_t HashName(const char* aName, uint16_t nameLen);
#ifdef XP_UNIX
static nsresult ResolveSymlink(const char *path);
#endif
class ZipArchiveLogger {
public:
@ -475,7 +472,6 @@ MOZ_WIN_MEM_TRY_CATCH(return nullptr)
// This extracts the item to the filehandle provided.
// If 'aFd' is null, it only tests the extraction.
// On extraction error(s) it removes the file.
// When needed, it also resolves the symlink.
//---------------------------------------------
nsresult nsZipArchive::ExtractFile(nsZipItem *item, const char *outname,
PRFileDesc* aFd)
@ -513,15 +509,11 @@ nsresult nsZipArchive::ExtractFile(nsZipItem *item, const char *outname,
}
}
//-- delete the file on errors, or resolve symlink if needed
//-- delete the file on errors
if (aFd) {
PR_Close(aFd);
if (rv != NS_OK)
PR_Delete(outname);
#ifdef XP_UNIX
else if (item->IsSymlink())
rv = ResolveSymlink(outname);
#endif
}
return rv;
@ -628,33 +620,6 @@ MOZ_WIN_MEM_TRY_CATCH(return NS_ERROR_FAILURE)
return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST;
}
#ifdef XP_UNIX
//---------------------------------------------
// ResolveSymlink
//---------------------------------------------
static nsresult ResolveSymlink(const char *path)
{
PRFileDesc * fIn = PR_Open(path, PR_RDONLY, 0000);
if (!fIn)
return NS_ERROR_FILE_DISK_FULL;
char buf[PATH_MAX+1];
int32_t length = PR_Read(fIn, (void*)buf, PATH_MAX);
PR_Close(fIn);
if (length <= 0) {
return NS_ERROR_FILE_DISK_FULL;
}
buf[length] = '\0';
if (PR_Delete(path) != 0 || symlink(buf, path) != 0) {
return NS_ERROR_FILE_DISK_FULL;
}
return NS_OK;
}
#endif
//***********************************************************
// nsZipArchive -- private implementation
//***********************************************************
@ -1163,14 +1128,6 @@ PRTime nsZipItem::LastModTime()
return GetModTime(Date(), Time());
}
#ifdef XP_UNIX
bool nsZipItem::IsSymlink()
{
if (isSynthetic) return false;
return (xtoint(central->external_attributes+2) & S_IFMT) == S_IFLNK;
}
#endif
nsZipCursor::nsZipCursor(nsZipItem *item, nsZipArchive *aZip, uint8_t* aBuf,
uint32_t aBufSize, bool doCRC)
: mItem(item)

View File

@ -81,10 +81,6 @@ public:
const uint8_t* GetExtraField(uint16_t aTag, uint16_t *aBlockSize);
PRTime LastModTime();
#ifdef XP_UNIX
bool IsSymlink();
#endif
nsZipItem* next;
const ZipCentral* central;
uint16_t nameLength;

View File

@ -5,8 +5,7 @@
const ARCHIVE = "zips/zen.zip";
const SUBDIR = "zen";
const SYMLINK = "beyond_link";
const ENTRIES = ["beyond.txt", SYMLINK, "waterwood.txt"];
const ENTRIES = ["beyond.txt", "waterwood.txt"];
Components.utils.import("resource://gre/modules/ZipUtils.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");
@ -28,20 +27,6 @@ function ensureExtracted(target) {
}
}
function ensureHasSymlink(target) {
// Just bail out if running on Windows, since symlinks do not exists there.
if (Services.appinfo.OS === "WINNT") {
return;
}
let entry = target.clone();
entry.append(SYMLINK);
do_print("ENTRY " + entry.path);
do_check_true(entry.exists());
do_check_true(entry.isSymlink());
}
add_task(function test_extractFiles() {
let target = dir.clone();
target.append("test_extractFiles");
@ -53,7 +38,6 @@ add_task(function test_extractFiles() {
}
ensureExtracted(target);
ensureHasSymlink(target);
});
add_task(async function test_extractFilesAsync() {