Beispiel #1
0
void removeSegmentInfoInformation(RVMINFO* currNode, const char* segment) {
    char* segInfoFileName = combinePaths(currNode->directory, SEGINFO_FILE);
    FILE* fd = fopen(segInfoFileName, "r");
    if (fd) {
        char line[1024];
        char *tempFileName = combinePaths(currNode->directory, "lrvmSEGINFO""tmp");
        FILE* tempFIleFd = fopen(tempFileName, "w");
        while (readLineFromFile(fd,line,sizeof(line))) {
            if (startsWith(SEGNAMESTR, line) && !strcmp(line + strlen(SEGNAMESTR), segment)) {
                readLineFromFile(fd,line,sizeof(line));
            } else {
                fprintf(tempFIleFd, "%s\n", line);
            }
        }
        fclose(tempFIleFd);
        fclose(fd);
        copyFile(tempFileName, segInfoFileName);
        deleteFile(tempFileName);
        free(tempFileName);
        char* targetSegmentFile = combinePaths(currNode->directory, segment);

        //Delete the backing store
        deleteFile(targetSegmentFile);
        free(targetSegmentFile);
    }
    free(segInfoFileName);
}
Beispiel #2
0
int isSegmentExists(const char *directory, const char *segment, unsigned long *size) {
    int toRet = 0;
    char* segInfoFileName = combinePaths(directory, SEGINFO_FILE);
    struct stat fileInfo;
    if (!stat(segInfoFileName, &fileInfo)) {
        FILE* fd = fopen(segInfoFileName, "r");
        if (fd) {
            char line[1024];
            while (readLineFromFile(fd,line,sizeof(line))) {
                if (startsWith(SEGNAMESTR, line) && !strcmp(line + strlen(SEGNAMESTR), segment)) {
                    //We found the segment, read the size
                    toRet = 1;
                    readLineFromFile(fd,line,sizeof(line));
                    *size = atol(line + strlen(SEGSIZESTR));
                    break;
                }
            }
            fclose(fd);
        } else {
            fprintf(stderr, "Corrupted File:Problem occured while trying to open seg info file:%s\n", segInfoFileName);
            remove(segInfoFileName);
            createFile(segInfoFileName);
        }

    } else {
        createFile(segInfoFileName);
    }
    free(segInfoFileName);
    return toRet;
}
Beispiel #3
0
void createNewSegment(const char *directory, const char *segment, unsigned long size, int extendSegment) {
    char* segInfoFileName = combinePaths(directory, SEGINFO_FILE);
    FILE* fd = fopen(segInfoFileName, "r");
    if (fd) {
        char line[1024];
        char *tempFileName = combinePaths(directory, "lrvmSEGINFO""tmp");
        FILE* tempFIleFd = fopen(tempFileName, "w");
        while (readLineFromFile(fd,line,sizeof(line))) {
            if (startsWith(SEGNAMESTR, line) && !strcmp(line + strlen(SEGNAMESTR), segment)) {
                readLineFromFile(fd,line,sizeof(line));
                fprintf(tempFIleFd, "%s%s\n", SEGNAMESTR, segment);
                sprintf(line, "%s%lu", SEGSIZESTR, size);
                fprintf(tempFIleFd, "%s\n", line);
            } else {
                fprintf(tempFIleFd, "%s\n", line);
            }
        }
        if (!extendSegment) {
            fprintf(tempFIleFd, "%s%s\n", SEGNAMESTR, segment);
            sprintf(line, "%s%lu", SEGSIZESTR, size);
            fprintf(tempFIleFd, "%s\n", line);
        }
        fclose(tempFIleFd);
        fclose(fd);
        copyFile(tempFileName, segInfoFileName);
        deleteFile(tempFileName);
        free(tempFileName);

    } else {
        fprintf(stderr, "STDERR:unable to read seg info file\n");
        abort();
    }

    free(segInfoFileName);
    struct stat fileInfo;
    char* targetSegmentFile = combinePaths(directory, segment);
    if (extendSegment && !stat(targetSegmentFile, &fileInfo)) {
        char tempSegFileName[1024];
        sprintf(tempSegFileName, "%s/%s%s%s", directory, SEGINFO_FILE, segment, "tmp");
        copyExtended(targetSegmentFile, tempSegFileName, size);
        copyFile(tempSegFileName, targetSegmentFile);
        deleteFile(tempSegFileName);
    } else {
        createNullFile(targetSegmentFile, size);
    }
    free(targetSegmentFile);
}
Beispiel #4
0
		//Gets a list of all files in the directory, excluding any subfolders in the directory
		static vector<string> getAllFilesInDir(string directory)
		{
			vector<string> validFiles;
			DIR* testDir;
			dirent* entry;
			testDir = opendir(directory.c_str());
			while ((entry = readdir(testDir)))
			{
				string fullPath = combinePaths(directory, string(entry->d_name));

				struct stat dirInfo;
				bool err = (stat(fullPath.c_str(), &dirInfo) != 0);
				bool isDir = S_ISDIR(dirInfo.st_mode);
				bool aFile = !(err || isDir);
				if (aFile)
					validFiles.push_back(fullPath);

			}
			closedir(testDir);
			return validFiles;
		}
bool includeLibraryIfExists(MavenCompiler* c, string import) {
	string look = combinePaths(c->binDirectory, c->iniFile.getKey("directories.lib")) + import + ".o";
	if(fileExists(look))
		c->extraLibraries.push(look);
	return true;
}