Esempio n. 1
0
def get_and_update_cached_file(file_url):
    """Returns cached file for the given URL only if the file exists."""
    cached_file = CachedFile.get(file_url)
    if cached_file:
        # check if the file still exists and remove the object from the DB otherwise
        if os.path.isfile(app.config['CACHE_DIR'] + cached_file.filename):
            return cached_file
        CachedFile.delete(cached_file)  # else
    return None
def get_and_update_cached_file(file_url):
    """Returns cached file for the given URL only if the file exists."""
    cached_file = CachedFile.get(file_url)
    if cached_file:
        # check if the file still exists and remove the object from the DB otherwise
        if os.path.isfile(app.config['CACHE_DIR'] + cached_file.filename):
            return cached_file
        CachedFile.delete(cached_file)  # else
    return None
def delete_file(cached_file):
    try:
        os.remove(app.config['CACHE_DIR'] + cached_file.filename)
        CachedFile.delete(cached_file)
    except OSError as e:  # E.g., if the file does not exist.
        if e.errno==errno.ENOENT:
            # We wanted to delete it anyway so go ahead
            CachedFile.delete(cached_file)
        else: raise  # E.g., permission denied
Esempio n. 4
0
def delete_file(cached_file):
    try:
        os.remove(app.config['CACHE_DIR'] + cached_file.filename)
        CachedFile.delete(cached_file)
    except OSError as e:  # E.g., if the file does not exist.
        if e.errno == errno.ENOENT:
            # We wanted to delete it anyway so go ahead
            CachedFile.delete(cached_file)
        else:
            raise  # E.g., permission denied