예제 #1
0
파일: views.py 프로젝트: hilerchyn/seahub
    def post(self, request):
        src_repo_id = request.POST.get('src_repo')
        src_dir     = unquote(request.POST.get('src_dir')).decode('utf-8')
        dst_repo_id = request.POST.get('dst_repo')
        dst_dir     = unquote(request.POST.get('dst_dir')).decode('utf-8')
        op          = request.POST.get('operation')
        obj_names   = request.POST.get('obj_names')

        if not (src_repo_id and src_dir  and dst_repo_id \
                and dst_dir and op and obj_names):
            return api_error(request, '400')

        if src_repo_id == dst_repo_id and src_dir == dst_dir:
            return api_error(request, '419', 'The src_dir is same to dst_dir')

        names = obj_names.split(':')
        names = map(lambda x: unquote(x).decode('utf-8'), names)

        if dst_dir.startswith(src_dir):
            for obj_name in names:
                if dst_dir.startswith('/'.join([src_dir, obj_name])):
                    return api_error(request, '419', 'Can not move a dirctory to its subdir')

        for obj_name in names:
            new_obj_name = check_filename_with_rename(dst_repo_id, dst_dir, obj_name)

            try:
                if op == 'cp':
                    seafserv_threaded_rpc.copy_file (src_repo_id, src_dir, obj_name,
                                                     dst_repo_id, dst_dir, new_obj_name,
                                                     request.user.username)
                elif op == 'mv':
                    seafserv_threaded_rpc.move_file (src_repo_id, src_dir, obj_name,
                                                     dst_repo_id, dst_dir, new_obj_name,
                                                     request.user.username)
            except SearpcError, e:
                return api_error(request, '419', "SearpcError:" + e.msg)
예제 #2
0
            # if dst_dir.startswith(src_dir):
            #     for obj_name in names:
            #         if dst_dir.startswith('/'.join([src_dir, obj_name])):
            #             return api_error(status.HTTP_409_CONFLICT,
            #                              'Can not move a dirctory to its subdir')

            filename = os.path.basename(path)
            filename_utf8 = filename.encode('utf-8')
            new_filename = check_filename_with_rename(dst_repo_id, dst_dir,
                                                      filename)
            new_filename_utf8 = new_filename.encode('utf-8')

            try:
                seafserv_threaded_rpc.move_file(src_repo_id, src_dir_utf8,
                                                filename_utf8, dst_repo_id,
                                                dst_dir_utf8,
                                                new_filename_utf8,
                                                request.user.username)
            except SearpcError, e:
                return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
                                 "SearpcError:" + e.msg)

            if request.GET.get('reloaddir', '').lower() == 'true':
                return reloaddir(request, dst_repo_id, dst_dir)
            else:
                resp = Response('success',
                                status=status.HTTP_301_MOVED_PERMANENTLY)
                uri = reverse('FileView', args=[repo_id], request=request)
                resp['Location'] = uri + '?p=' + quote(dst_dir_utf8) + quote(
                    new_filename_utf8)
                return resp
예제 #3
0
            # if dst_dir.startswith(src_dir):
            #     for obj_name in names:
            #         if dst_dir.startswith('/'.join([src_dir, obj_name])):
            #             return api_error(status.HTTP_409_CONFLICT,
            #                              'Can not move a dirctory to its subdir')
            
            filename = os.path.basename(path)
            filename_utf8 = filename.encode('utf-8')
            new_filename = check_filename_with_rename(dst_repo_id, dst_dir,
                                                      filename)
            new_filename_utf8 = new_filename.encode('utf-8')

            try:
                seafserv_threaded_rpc.move_file(src_repo_id, src_dir_utf8,
                                                filename_utf8, dst_repo_id,
                                                dst_dir_utf8, new_filename_utf8,
                                                request.user.username)
            except SearpcError, e:
                return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR,
                                 "SearpcError:" + e.msg)

            if request.GET.get('reloaddir', '').lower() == 'true':
                return reloaddir(request, dst_repo_id, dst_dir)
            else:
                resp = Response('success', status=status.HTTP_301_MOVED_PERMANENTLY)
                uri = reverse('FileView', args=[repo_id], request=request)
                resp['Location'] = uri + '?p=' + quote(dst_dir_utf8) + quote(new_filename_utf8)
                return resp
        elif operation.lower() == 'create':
            parent_dir = os.path.dirname(path)
            parent_dir_utf8 = parent_dir.encode('utf-8')