示例#1
0
	void CreateTestFileHardLink(const TCHAR *szOriginalFile, const TCHAR *szNewFileName)
	{
		TCHAR szCopy[MAX_PATH];
		TCHAR *szRet = PathCombine(szCopy, m_szResourceDirectory, szNewFileName);
		ASSERT_NE(nullptr, szRet);

		BOOL bRet = CreateHardLink(szCopy, szOriginalFile, NULL);
		ASSERT_NE(FALSE, bRet);
	}
示例#2
0
文件: FSFolder.c 项目: hernan604/lucy
static bool
S_hard_link(char *from8, char *to8) {
    if (CreateHardLink(to8, from8, NULL)) {
        return true;
    }
    else {
        char *win_error = Err_win_error();
        Err_set_error(Err_new(Str_newf("CreateHardLink for new file '%s' from '%s' failed: %s",
                                       to8, from8, win_error)));
        FREEMEM(win_error);
        return false;
    }
}
示例#3
0
BOOL CreateHardLinkOtherwiseCopy(const char *targetName, const char *linkName)
{
    BOOL result = CreateHardLink(linkName, targetName, NULL);
    if (!result) {
        DWORD errNr = GetLastError();
        if (errNr != ERROR_INVALID_FUNCTION) { /* In case a hardlink is not supported, e.g. FAT32. */
            printf("Windows System Error %d occurred during creation of link.\n", errNr);
        } else {
            BOOL FailIfExists = TRUE;
            result = CopyFile(targetName, linkName, FailIfExists);
            if (!result) {
                printf("Windows System Error %d occurred during copying of file.\n", GetLastError());
            }
        }
    }
    return result;
}
示例#4
0
BOOL WaitForSingleFile(_In_ LPCTTSTR lpPathName, _In_ DWORD dwNotifyFilter)
{
    UUIDCreate()
    StringFromCLSID
    GetTempPath(tmpdir, MAX_PATH);
    CreateDirectory(tmpdir+guid);
    CreateHardLink(tmpdir+guid+guid, srcpath, NULL);
    handle = FindFirstChangeNotification(tmpdir, FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE);
    if(handle == INVALID_HANDLE_VALUE)
    {
        printf("OHH NO\n");
        ExitProcess(1);
    }
    WaitForSingleObject(handle, INFINITE);

    DeleteFile(tmpdir+guid+guid);
    DeleteDirectory(tmpdir+guid);


}
示例#5
0
int
maildirFclose(FILE *fp, char *filename)
{
	char *tmp, *filename_new;

	if (fp == NULL || filename == NULL)
		goto error0;

	if ((filename_new = strdup(filename)) == NULL)
		goto error0;

	if ((tmp = strstr(filename_new, "/tmp/")) == NULL)
		goto error1;

	/* Replace "tmp" by "new" in filename_new. */
	memcpy(tmp+1, "new", sizeof ("new")-1);

#ifdef __unix__
	if (link(filename, filename_new))
		goto error1;
#endif
#ifdef __WIN32__
	if (!CreateHardLink(filename_new, filename, NULL))
		goto error1;
#endif

	if (fclose(fp))
		goto error1;

	(void) unlink(filename);
	free(filename);

	return 0;
error1:
	free(filename_new);
error0:
	return -1;
}
示例#6
0
int
link(const char* oldpath, const char* newpath)
{
	if (CreateHardLink(newpath, oldpath, NULL)) {
		return 0;
	}
	else {
		DWORD error = GetLastError();
		if (error == ERROR_FILE_NOT_FOUND) {
			errno = ENOENT;
		}
		else {
			// for anything but the ENOENT-equivalent, we'll
			// log the error and set errno to something generic-
			// sounding ("operation not permitted")
			dprintf(D_ALWAYS,
			        "link: CreateHardLink error: %u\n",
			        (unsigned)error);
			errno = EPERM;
		}
		return -1;
	}
}
示例#7
0
nfsstat3 CNFS3Prog::ProcedureLINK(void)
{
    PrintLog("LINK");
    char *filePath;
    diropargs3 link;
    std::string dirName;
    std::string fileName;
    nfsstat3 stat;
    post_op_attr obj_attributes;
    wcc_data dir_wcc;

    filePath = GetPath();
    ReadDirectory(dirName, fileName);

    char *linkFullPath = GetFullPath(dirName, fileName);

    if (CreateHardLink(linkFullPath, filePath, NULL) == 0) {
        stat = NFS3ERR_IO;
    }
    stat = CheckFile(linkFullPath);
    if (stat == NFS3_OK) {
        obj_attributes.attributes_follow = GetFileAttributesForNFS(filePath, &obj_attributes.attributes);

        if (!obj_attributes.attributes_follow) {
            stat = NFS3ERR_IO;
        }
    }

    dir_wcc.after.attributes_follow = GetFileAttributesForNFS((char*)dirName.c_str(), &dir_wcc.after.attributes);

    Write(&stat);
    Write(&obj_attributes);
    Write(&dir_wcc);

    return stat;
}
示例#8
0
bool FileSystem::link(const Path& old_path, const Path& new_path) {
  return CreateHardLink(new_path.c_str(), old_path.c_str(), NULL) == TRUE;
}
示例#9
0
/* Tag( external_link )
 */
int external_link (char *oldpath, char *newpath)
{
  return CreateHardLink (expand_file_name (newpath),
			 expand_file_name (oldpath), NULL);
}
示例#10
0
bool FileSystem::hardLinkFiles(File* file1, File* file2) {
	Statistics::getInstance()->hardLinks++;
	LPWSTR file1Name = new WCHAR[MAX_PATH_LENGTH];
	LPWSTR file2Name = new WCHAR[MAX_PATH_LENGTH];
	LPWSTR file2Backup = new WCHAR[MAX_PATH_LENGTH];

	file1->copyName(cleanString(file1Name));
	file2->copyName(cleanString(file2Name));
	logInfo(L"Linking %s and %s", file1Name, file2Name);

	// Step 1: precaution - rename original file
	wsprintf(file2Backup, L"%s.backup", file2Name);
	if (!MoveFile(file2Name, file2Backup)) {
		logError(L"Unable to move file to backup: %i", GetLastError());
		delete file1Name;
		delete file2Name;
		delete file2Backup;
		return false;
	}

	// Step 2: create hard link
	if (!CreateHardLink(file2Name, file1Name, NULL)) {
		logError(L"Unable to create hard link: %i", GetLastError());
		delete file1Name;
		delete file2Name;
		delete file2Backup;
		return false;
	}

	// Step 3: remove backup file (orphan)
	if (!DeleteFile(file2Backup)) {
		logError(L"Unable to delete file: %i, trying to change attribute...", GetLastError());

		if (!SetFileAttributes(file2Backup, FILE_ATTRIBUTE_NORMAL) ||
			!DeleteFile(file2Backup)) {

			logError(L"Finally unable to delete file: %i", GetLastError());
			delete file1Name;
			delete file2Name;
			delete file2Backup;
			return false;
		}
	}

	// Step 4: re-assign the old short file name
	// NOTE: This seems to be NOT possible! THis seems to be a NTFS Limitation, no hard link alternative file names are possible!
	//if (file2->getShortName() != NULL) {
	//	
	//	HANDLE hFile = CreateFile(file2Name, GENERIC_ALL, 0, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
	//	if (!SetFileShortName(hFile, file2->getShortName())) {
	//		logError(L"Unable to set the files short name to: \"%s\" Error: %i", file2->getShortName(), GetLastError());
	//	}
	//	CloseHandle(hFile);
	//}

	delete file1Name;
	delete file2Name;
	delete file2Backup;
	Statistics::getInstance()->hardLinksSuccess++;
	return true;
}