Minor questions in Linux file semantics

  • Post author:
  • Post category:Linux

I’ve known for a long time that if you delete a file on Unix / Linux but that file is open somewhere, the blocks used by the file aren’t freed until that user closes the file (or is terminated), but I was left wondering about some other edge cases.

Shaken Fist has a distributed blob store. It also has a cache of images that virtual machines are using. If the blob store and the image cache are on the same filesystem, sometimes the image cache entry can be a hard link to an entry in the blob store (for example, if the entry in the blob store doesn’t need to be transcoded before use by the virtual machine). However, if they are on different file systems, I instead use a symbolic link.

This raises questions — what happens if you rename a file which is open for writing in a program? What happens if you change a symbolic link to point somewhere else while it is open? I suspect in both cases the right thing happens, but I decided I should test these theories out.

(more…)

Continue ReadingMinor questions in Linux file semantics

Building a symlink tree for MythTV recordings

  • Post author:
  • Post category:Mythtv

I wanted to build a directory of symlinks that pointed to my MythTV recordings, so I wrote a little python script to do it for me. I figure someone else might find this useful too... #!/usr/bin/python # Copyright (C) Michael Still (mikal@stillhq.com) 2007 # Released under the terms of the GNU GPL import MySQLdb import os import re from socket import gethostname # Connect to the MythTV database based on the MythTV config config_values = {} home = os.environ.get('HOME') config = open(home + '/.mythtv/mysql.txt') for line in config.readlines(): if not line.startswith('#') and len(line) > 5: (key, value) = line.rstrip('\n').split('=') config_values[key] = value db_connection = MySQLdb.connect(host = config_values['DBHostName'], user = config_values['DBUserName'], passwd = config_values['DBPassword'], db = config_values['DBName']) cursor = db_connection.cursor(MySQLdb.cursors.DictCursor) # Regexp for what is allowed in the symlink name unsafe = re.compile('[^a-zA-Z0-9\-\:_]+') # Find the recordings directory -- this assumes you haven't used an # identifier string for this machine... cursor.execute('select * from settings where value="RecordFilePrefix" and ' 'hostname="%s";' % gethostname()) row = cursor.fetchone() basedir = row['data'] # Now find all the recordings we have at the moment cursor.execute('select title, subtitle, starttime, basename from recorded;') for i in range(cursor.rowcount): row = cursor.fetchone() title = row['title'] subtitle = row['subtitle'] if subtitle…

Continue ReadingBuilding a symlink tree for MythTV recordings

End of content

No more pages to load