~ubuntu-branches/ubuntu/trusty/pcmanfm/trusty-proposed

« back to all changes in this revision

Viewing changes to src/vfs/vfs-file-monitor.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Lee
  • Date: 2008-09-26 10:19:20 UTC
  • mfrom: (4.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080926101920-cfldybkmwgwrtv9u
Tags: 0.5-3
* Correct spellings,  03_correct_spelling.dpatch (Closes:498794) 
* Code in some files are taken from other projects, added these
  informations into copyright file. (Closes:499678)
* Applied 04_defaut_terminal.dpatch to support x-terminal-emulator
  alternative. (Closes:497494) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#endif
21
21
 
22
22
#include "vfs-file-monitor.h"
 
23
#include "vfs-file-info.h"
23
24
#include <sys/types.h>  /* for stat */
24
25
#include <sys/stat.h>
25
26
#include <errno.h>
79
80
    FAMNoExists( &fam );  /* This is an extension of gamin */
80
81
#endif
81
82
 
82
 
    fam_io_channel = g_io_channel_unix_new( fam.fd );
 
83
    fam_io_channel = g_io_channel_unix_new( FAMCONNECTION_GETFD( &fam ) );
83
84
#endif
84
85
 
 
86
    /* set fam socket to non-blocking */
 
87
    /* fcntl( FAMCONNECTION_GETFD( &fam ),F_SETFL,O_NONBLOCK); */
 
88
 
85
89
    g_io_channel_set_encoding( fam_io_channel, NULL, NULL );
86
90
    g_io_channel_set_buffered( fam_io_channel, FALSE );
87
91
    g_io_channel_set_flags( fam_io_channel, G_IO_FLAG_NONBLOCK, NULL );
88
92
 
89
93
    fam_io_watch = g_io_add_watch( fam_io_channel,
90
 
                                   G_IO_IN | G_IO_PRI | G_IO_HUP,
 
94
                                   G_IO_IN | G_IO_PRI | G_IO_HUP|G_IO_ERR,
91
95
                                   on_fam_event,
92
96
                                   NULL );
93
97
    return TRUE;
136
140
}
137
141
 
138
142
VFSFileMonitor* vfs_file_monitor_add( char* path,
 
143
                                      gboolean is_dir,
139
144
                                      VFSFileMonitorCallback cb,
140
145
                                      gpointer user_data )
141
146
{
142
147
    VFSFileMonitor * monitor;
143
148
    VFSFileMonitorCallbackEntry cb_ent;
144
 
    gboolean add_new = FALSE;
145
149
    struct stat file_stat;
146
 
    gboolean is_dir;
147
150
    gchar* real_path = NULL;
148
151
 
149
152
    if ( ! monitor_hash )
150
 
    {
151
 
        if ( !vfs_file_monitor_init() )
152
 
            return NULL;
153
 
    }
 
153
        return NULL;
154
154
 
155
155
    monitor = ( VFSFileMonitor* ) g_hash_table_lookup ( monitor_hash, path );
156
156
    if ( ! monitor )
157
157
    {
158
158
        monitor = g_slice_new0( VFSFileMonitor );
159
159
        monitor->path = g_strdup( path );
 
160
 
160
161
        monitor->callbacks = g_array_new ( FALSE, FALSE, sizeof( VFSFileMonitorCallbackEntry ) );
161
162
        g_hash_table_insert ( monitor_hash,
162
163
                              monitor->path,
163
164
                              monitor );
164
 
        is_dir = ( stat( path, &file_stat ) == 0 && S_ISDIR(file_stat.st_mode) );
165
165
 
166
166
        /* NOTE: Since gamin, FAM and inotify don't follow symlinks,
167
167
                 we need to do some special processing here. */
172
172
            {
173
173
                char* link = g_file_read_link( link_file, NULL );
174
174
                char* dirname = g_path_get_dirname( link_file );
175
 
                g_free( real_path );
176
175
                real_path = vfs_file_resolve_path( dirname, link );
177
176
                g_free( link );
178
177
                g_free( dirname );
206
205
                            real_path ? real_path : path,
207
206
                            &monitor->request,
208
207
                            monitor );
209
 
 
210
 
 
211
208
        }
212
209
#endif
213
210
        g_free( real_path );
215
212
 
216
213
    if( G_LIKELY(monitor) )
217
214
    {
 
215
        /* g_debug( "monitor installed: %s, %p", path, monitor ); */
218
216
        if ( cb )
219
217
        { /* Install a callback */
220
218
            cb_ent.callback = cb;
221
219
            cb_ent.user_data = user_data;
222
220
            monitor->callbacks = g_array_append_val( monitor->callbacks, cb_ent );
223
221
        }
224
 
        ++monitor->n_ref;
 
222
        g_atomic_int_inc( &monitor->n_ref );
225
223
    }
226
 
 
227
224
    return monitor;
228
225
}
229
226
 
246
243
            }
247
244
        }
248
245
    }
249
 
    --fm->n_ref;
250
 
    if ( 0 == fm->n_ref )
 
246
 
 
247
    if ( g_atomic_int_dec_and_test( &fm->n_ref ) )
251
248
    {
252
249
#ifdef USE_INOTIFY /* Linux inotify */
253
250
        inotify_rm_watch ( inotify_fd, fm->wd );
357
354
    char buf[ BUF_LEN ];
358
355
    int i, len;
359
356
#else /* FAM|gamin */
360
 
 
361
357
    FAMEvent evt;
362
358
#endif
363
359
 
364
360
    VFSFileMonitor* monitor = NULL;
365
361
 
366
 
    if ( cond & G_IO_HUP )
 
362
    if ( cond & (G_IO_HUP | G_IO_ERR) )
367
363
    {
368
364
        disconnect_from_fam();
369
365
        if ( g_hash_table_size ( monitor_hash ) > 0 )
377
373
            g_hash_table_foreach( monitor_hash, ( GHFunc ) reconnect_fam, NULL );
378
374
        }
379
375
        return TRUE; /* don't need to remove the event source since
380
 
                                                                                                                    it has been removed by disconnect_from_fam(). */
 
376
                                    it has been removed by disconnect_from_fam(). */
381
377
    }
382
378
 
383
379
#ifdef USE_INOTIFY /* Linux inotify */
439
435
                /* Call the callback functions */
440
436
                dispatch_event( monitor, evt.code, evt.filename );
441
437
                break;
 
438
                /* Other events are not supported */
442
439
            default:
443
 
                return TRUE;  /* Other events are not supported */
 
440
                break;
444
441
            }
445
442
        }
446
443
    }