示例#1
0
def check_if_file_exists(filepath):

    #try to open the file specified, if it fails, then it doens't exist
    try:
        lindfd = lind_fs_calls.open_syscall(filepath, O_RDONLY, 0)
        lind_fs_calls.close_syscall(lindfd)
        #file found, return true
        return True
    except lind_fs_calls.SyscallError:
        #file not found, return false
        return False
示例#2
0
        #print "in copy " + source+ "..." + str(mode) + "..." + str(stat.S_IRWXU)
        lindfd = lind_fs_calls.open_syscall(path + "/" + new_name, O_CREAT | O_RDWR, mode)

    except lind_fs_calls.SyscallError, e:
        print "Could not open the local file. Error: %s" % e
        return -1

    #try to write the file content to the newly file
    try:
        lind_fs_calls.write_syscall(lindfd, filedata.read())
    except lind_fs_calls.SyscallError, e:
        print "Could not write file. Error: %s" % e
        return -1


    lind_fs_calls.close_syscall(lindfd)

#pass in a path, check if it exists in the virtual fs. if it doesnt, it creates the path
def check_path_exists(path):
    path_list = path.split("/")[0:-1]#get each directory in the path, excluding the new file's name
    lind_fs_calls.chdir_syscall("/")#start at root
    path_str = "/"#this string will hold the whole path of the destination file (excluding the filename itself)

    #loop through each dir in the path
    for p in path_list:
        if(p == ""):
            continue
        path_str += (p + "/")#concat the dir to the full path string
        #try to chdir (if it fails, means the directory doesnt exist)
        try:
            lind_fs_calls.chdir_syscall(p)